/*
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * DMGIS. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with DMGIS.
 *
 */
package com.dmgis.qxfw.dataservice.businessservice.qxinfo.service.impl;


import com.dmgis.entity.DmMapRectangle;
import com.dmgis.entity.DmMapPoint;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataBySelect;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.contour_setting;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.base_product;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.hydropower_info;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.thunder_fcst;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.ActualElemQuery;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.RadarSearch;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.ResultObj;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.SateSearch;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.*;
import com.dmgis.qxfw.dataservice.businessservice.common.util.*;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.FileRequestService;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.businessservice.qxinfo.pojo.GridData;
import com.dmgis.qxfw.dataservice.businessservice.qxinfo.pojo.WeatherVo;
import com.dmgis.qxfw.dataservice.businessservice.qxinfo.service.IQxInfoService;
import com.dmgis.qxfw.dataservice.gisservice.service.ITransformService;
import com.dmgis.qxfw.dataservice.pages.service.impl.ComDisplayServiceImpl;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.Date;



/**
 * This class is used for 气象信息展示
 */
@Service("QxInfoService")
public class QxInfoServiceImpl implements IQxInfoService {
    @Resource
    private ITransformService iTransformService;
    private static final Logger log = Logger.getLogger(ComDisplayServiceImpl.class);

    ProcessRequestController pc = new ProcessRequestController();
    //MongoService1 ms = new MongoService1();
    FileRequestService ms = new FileRequestService();
    @Override
    public collectTime getCityNewDate() {
        // TODO 获取城镇预报最新时间
        collectTime newDate = new collectTime();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        String[] columns = new String[]{"to_char(pausetime, 'yyyy-MM-dd HH24:MI:SS') as pausetime"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format(" type='CITYTV'"));
        selectRequest.setSort(new String[]{"pausetime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "collect_time");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<collectTime>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return newDate;
    }

    @Override
    public List<ForecastInfo> getCityFcst(TownshipForecastKey newestDate) {
        // TODO 获取城市预报
        List<ForecastInfo> resultList = new ArrayList<ForecastInfo>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("weather1");
        columns.add("weather2");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("wind1");
        columns.add("wind2");
        columns.add("windd1");
        columns.add("windd2");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(newestDate.getStationID())) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", newestDate.getStationID()));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() > 0) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", newestDate.getNTimes(),
                    newestDate.getNTimes() - 24));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        if (StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere.append(
                    String.format(" stationid like '5%%' and stationname like '%s%%' ", DbConfig.COUNTY));
        }
        strWhere.append(
                String.format(" and stationid like '5%%' and stationname like '%s%%' ", DbConfig.COUNTY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            if (newestDate.getDateChar() != null && DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "forecastinfo");
            } else {
                selectParam.put("method", "forecastinfo");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ForecastInfo>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public TownshipForecastKey getTownNewDate() {
        // TODO 获取乡镇预报最新时间
        TownshipForecastKey newDate = new TownshipForecastKey();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
         selectRequest.setParam(String.format("city like '%s%%'",
         DbConfig.CITY));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "township_forecast_province");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecastKey>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setDateChar(DateTime.now().toDate());
            Integer time = DateTime.now().GetHour() >= 8 && DateTime.now().GetHour() < 20 ? 8 : 20;
            String timechar = "";
            if (time < 10) {
                timechar = "08";
            }
            newDate.setTimeChar(timechar);
        }
        return newDate;
    }

    @Override
    public List<TownshipForecast> getTownshipFcst(TownshipForecastKey newestDate, String county) {
        // TODO 获取乡镇预报最新数据
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("CAST(replace(cast(humid AS VARCHAR),'-65535','99999') as numeric(18,1)) as humid");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("weather1");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(newestDate.getStationID())) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", newestDate.getStationID()));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() > 0) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", newestDate.getNTimes(),
                    newestDate.getNTimes() - 24));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and areaname like '%s%%'", DbConfig.COUNTY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            if (DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast_province");
            } else {
                selectParam.put("method", "township_forecast_province");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public DopplerKey getRadarNewestDate() {
        // TODO 获取雷达图最新时间
        // DbContextHolder.setDbType("qx");
        // return forecastInfoDao.getRadarNewestDate();
        DopplerKey result = new DopplerKey();
        doppler newDate = new doppler();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "doppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setDatechar(DateTime.now().toDate());
        }
        if (newDate != null) {
            result.setDateChar(newDate.getDatechar());
            result.setTimeChar(newDate.getTimechar());
        }
        return result;
    }

    @Override
    public List<DopplerKey> getRadarTypes(Date doppleTime) {
        // TODO 获取雷达图参数
        List<doppler> listData = new ArrayList<doppler>();
        List<DopplerKey> resultList = new ArrayList<DopplerKey>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"distinct ldtype", "Elevation"};
        selectRequest.setSort(new String[]{"ldtype asc", "elevation asc"});
        selectRequest.setColumns(columns);
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (doppleTime != null) {
            whereCount++;
            strWhere.append(String.format(" dateChar>='%tF'", doppleTime));
        }
        strWhere.append(" and stationid = '" + DbConfig.radarid + "'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "doppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (doppler dop : listData) {
                DopplerKey dopplerKey = new DopplerKey();
                dopplerKey.setElevation(dop.getElevation());
                dopplerKey.setStationId(dop.getStationid());
                dopplerKey.setType(dop.getLdtype());
                resultList.add(dopplerKey);
            }
        }
        return resultList;
    }
    @Override
    public List<Doppler> getNewRadarInfo(RadarSearch radarSearch) {
        // TODO 获取雷达图信息
        List<doppler> listData = new ArrayList<doppler>();
        List<Doppler> resultList = new ArrayList<Doppler>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("TimeChar");
        columns.add("StationId");
        columns.add("LdType");
        columns.add("Elevation");
        columns.add("Path");
        columns.add("jwImgPath");
        columns.add("RadTitle");
        columns.add("west");
        columns.add("south");
        columns.add("east");
        columns.add("north");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc limit 10"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (radarSearch.getDataYear() != null) {
            strWhere.append(String.format("dataYear='%d'", radarSearch.getDataYear()));
            whereCount++;
        }
        if (radarSearch.getDateChar() != null) {
            strWhere.append(String.format(" and dateChar='%tF'", radarSearch.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(radarSearch.getTimeChar())) {
            strWhere.append(String.format(" and timeChar='%s'", radarSearch.getTimeChar()));
        }
        if (!StringUtil.IsNullOrEmpty(radarSearch.getStationId())) {
            strWhere.append(String.format(" and stationId='%s'", radarSearch.getStationId()));
        }
        if (!StringUtil.IsNullOrEmpty(radarSearch.getType())) {
            strWhere.append(String.format(" and ldtype='%s'", radarSearch.getType()));
        }
        if (radarSearch.getElevation() != null) {
            strWhere.append(String.format(" and elevation='%1.1f'", radarSearch.getElevation()));
        }
        strWhere.append("  and  state='1' ");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "doppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (doppler dop : listData) {
                Doppler doppler = new Doppler();
                doppler.setDateChar(dop.getDatechar());
                doppler.setTimeChar(dop.getTimechar());
                doppler.setStationId(dop.getStationid());
                doppler.setType(dop.getLdtype());
                doppler.setElevation(dop.getElevation());
                doppler.setPath(dop.getPath());
                doppler.setJwImgPath(dop.getJwimgpath());
                doppler.setRadTitle(dop.getRadtitle());
                doppler.setFxmin(dop.getWest());
                doppler.setFxmax(dop.getEast());
                doppler.setFymin(dop.getSouth());
                doppler.setFymax(dop.getNorth());
                resultList.add(doppler);
            }
        }
        return resultList;
    }

    @Override
    public List<SatelliteNephoram> getYtInfo(SateSearch sateSearch) {
        // TODO 获取云图信息
        List<satellitenephoram> listData = new ArrayList<satellitenephoram>();
        List<SatelliteNephoram> resultList = new ArrayList<SatelliteNephoram>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("TimeChar");
        columns.add("ytType");
        columns.add("Path");
        columns.add("jwImgPath");
        columns.add("SateTitle");
        columns.add("west");
        columns.add("south");
        columns.add("east");
        columns.add("north");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc limit 10"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append("state=1");
        int whereCount = 0;
        if (sateSearch.getDataYear() != null) {
            strWhere.append(String.format("and  dataYear='%d'", sateSearch.getDataYear()));
            whereCount++;
        }
        if (sateSearch.getDateChar() != null) {
            strWhere.append(String.format(" and dateChar='%tF'", sateSearch.getDateChar()));
        }
        if (sateSearch.getStartDate() != null) {
            strWhere.append(String.format(
                    " and (cast(datechar as timestamp)+ CAST(SUBSTRING(TimeChar,1,2)||'hour' as INTERVAL))>='%s'",
                    sateSearch.getStartDate()));
        }
        if (sateSearch.getEndDate() != null) {
            strWhere.append(String.format(
                    " and (cast(datechar as timestamp)+ CAST(SUBSTRING(TimeChar,1,2)||'hour' as INTERVAL))<='%s'",
                    sateSearch.getEndDate()));
        }
        if (!StringUtil.IsNullOrEmpty(sateSearch.getTimeChar())) {
            strWhere.append(String.format(" and timeChar='%s'", sateSearch.getTimeChar()));
        }
        if (!StringUtil.IsNullOrEmpty(sateSearch.getType())) {
            strWhere.append(String.format(" and yttype like '%%%s%%'", sateSearch.getType()));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "satellitenephoram");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<satellitenephoram>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (satellitenephoram sate : listData) {
                SatelliteNephoram satellite = new SatelliteNephoram();
                satellite.setDateChar(sate.getDatechar());
                satellite.setTimeChar(sate.getTimechar());
                satellite.setType(sate.getYttype());
                satellite.setPath(sate.getPath());
                satellite.setJwImgPath(sate.getJwimgpath());
                satellite.setSateTitle(sate.getSatetitle());
                satellite.setFxmin(sate.getWest());
                satellite.setFxmax(sate.getEast());
                satellite.setFymin(sate.getSouth());
                satellite.setFymax(sate.getNorth());
                resultList.add(satellite);
            }
        }
        return resultList;
    }

    @Override
    public List<Doppler> getRadarInfo(RadarSearch radarSearch) {
        // TODO 获取雷达图信息
        List<doppler> listData = new ArrayList<doppler>();
        List<Doppler> resultList = new ArrayList<Doppler>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("TimeChar");
        columns.add("StationId");
        columns.add("LdType");
        columns.add("Elevation");
        columns.add("Path");
        columns.add("jwImgPath");
        columns.add("RadTitle");
        columns.add("west");
        columns.add("south");
        columns.add("east");
        columns.add("north");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (radarSearch.getDataYear() != null) {
            strWhere.append(String.format("dataYear='%d'", radarSearch.getDataYear()));
            whereCount++;
        }
        if (radarSearch.getDateChar() != null) {
            strWhere.append(String.format(" and dateChar='%tF'", radarSearch.getDateChar()));
        }
        if (radarSearch.getStartDate() != null) {
            strWhere.append(String.format(
                    " and (cast(datechar as timestamp)+ CAST(SUBSTRING(TimeChar,1,2)||'hour' as INTERVAL))>='%s'",
                    radarSearch.getStartDate()));
        }
        if (radarSearch.getEndDate() != null) {
            strWhere.append(String.format(
                    " and (cast(datechar as timestamp)+ CAST(SUBSTRING(TimeChar,1,2)||'hour' as INTERVAL))<='%s'",
                    radarSearch.getEndDate()));
        }
        if (!StringUtil.IsNullOrEmpty(radarSearch.getTimeChar())) {
            strWhere.append(String.format(" and timeChar='%s'", radarSearch.getTimeChar()));
        }
        if (!StringUtil.IsNullOrEmpty(radarSearch.getStationId())) {
            strWhere.append(String.format(" and stationId='%s'", radarSearch.getStationId()));
        }
        if (!StringUtil.IsNullOrEmpty(radarSearch.getType())) {
            strWhere.append(String.format(" and ldtype='%s'", radarSearch.getType()));
        }
        if (radarSearch.getElevation() != null) {
            strWhere.append(String.format(" and elevation='%1.1f'", radarSearch.getElevation()));
        }
        strWhere.append("  and  state='1' ");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "doppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (doppler dop : listData) {
                Doppler doppler = new Doppler();
                doppler.setDateChar(dop.getDatechar());
                doppler.setTimeChar(dop.getTimechar());
                doppler.setStationId(dop.getStationid());
                doppler.setType(dop.getLdtype());
                doppler.setElevation(dop.getElevation());
                doppler.setPath(dop.getPath());
                doppler.setJwImgPath(dop.getJwimgpath());
                doppler.setRadTitle(dop.getRadtitle());
                doppler.setFxmin(dop.getWest());
                doppler.setFxmax(dop.getEast());
                doppler.setFymin(dop.getSouth());
                doppler.setFymax(dop.getNorth());
                resultList.add(doppler);
            }
        }
        return resultList;
    }

    @Override
    public SatelliteNephoramKey getSateNewestDate() {
        // TODO 获取云图最新时间
        SatelliteNephoramKey result = new SatelliteNephoramKey();
        satellitenephoram data = new satellitenephoram();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "satellitenephoram");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            data = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<satellitenephoram>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            data.setDatechar(DateTime.now().toDate());
        }
        if (data != null) {
            result.setDateChar(data.getDatechar());
            result.setTimeChar(data.getTimechar());
        }
        return result;
    }

    @Override
    public List<String> getSateTypes() {
        // TODO 获取云图类型
        List<satellitenephoram> listData = new ArrayList<satellitenephoram>();
        List<String> resultList = new ArrayList<String>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"distinct yttype"};
        selectRequest.setColumns(columns);
        try {
            selectParam.put("method", "satellitenephoram");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<satellitenephoram>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (satellitenephoram sate : listData) {
                resultList.add(sate.getYttype());
            }
        }
        return resultList;
    }

    @Override
    public List<SatelliteNephoram> getSateInfo(SateSearch sateSearch) {
        // TODO 获取云图信息
        List<satellitenephoram> listData = new ArrayList<satellitenephoram>();
        List<SatelliteNephoram> resultList = new ArrayList<SatelliteNephoram>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("TimeChar");
        columns.add("ytType");
        columns.add("Path");
        columns.add("jwImgPath");
        columns.add("SateTitle");
        columns.add("fwest");
        columns.add("fsouth");
        columns.add("feast");
        columns.add("fnorth");
        columns.add("west");
        columns.add("south");
        columns.add("east");
        columns.add("north");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append("state=1");
        int whereCount = 0;
        if (sateSearch.getDataYear() != null) {
            strWhere.append(String.format("and  dataYear='%d'", sateSearch.getDataYear()));
            whereCount++;
        }
        if (sateSearch.getDateChar() != null) {
            strWhere.append(String.format(" and dateChar='%tF'", sateSearch.getDateChar()));
        }
        if (sateSearch.getStartDate() != null) {
            strWhere.append(String.format(
                    " and (cast(datechar as timestamp)+ CAST(SUBSTRING(TimeChar,1,2)||'hour' as INTERVAL))>='%s'",
                    sateSearch.getStartDate()));
        }
        if (sateSearch.getEndDate() != null) {
            strWhere.append(String.format(
                    " and (cast(datechar as timestamp)+ CAST(SUBSTRING(TimeChar,1,2)||'hour' as INTERVAL))<='%s'",
                    sateSearch.getEndDate()));
        }
        if (!StringUtil.IsNullOrEmpty(sateSearch.getTimeChar())) {
            strWhere.append(String.format(" and timeChar='%s'", sateSearch.getTimeChar()));
        }
        if (!StringUtil.IsNullOrEmpty(sateSearch.getType())) {
            strWhere.append(String.format(" and yttype='%s'", sateSearch.getType()));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "satellitenephoram");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<satellitenephoram>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (satellitenephoram sate : listData) {
                SatelliteNephoram satellite = new SatelliteNephoram();
                satellite.setDateChar(sate.getDatechar());
                satellite.setTimeChar(sate.getTimechar());
                satellite.setType(sate.getYttype());
                satellite.setPath(sate.getPath());
                satellite.setJwImgPath(sate.getJwimgpath());
                satellite.setSateTitle(sate.getSatetitle());
                satellite.setFxmin(sate.getFwest());
                satellite.setFxmax(sate.getFeast());
                satellite.setFymin(sate.getFsouth());
                satellite.setFymax(sate.getFnorth());
                satellite.setXmin(sate.getWest());
                satellite.setXmax(sate.getEast());
                satellite.setYmin(sate.getSouth());
                satellite.setYmax(sate.getNorth());
                resultList.add(satellite);
            }
        }
        return resultList;
    }

    @Override
    public collectTime getScaleNewDate(String type) {
        // TODO 获取最新实况数据
        Date date = new Date();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"year", "month", "day", "hour"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format(" type='%s'", type));
        selectRequest.setSort(new String[]{"pausetime desc"});
        selectRequest.setLimit(1);
        collectTime time = new collectTime();
        try {
            selectParam.put("method", "collect_time");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            time = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<collectTime>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return time;
    }

    @Override
    public List<ActualData> qxElementQuery(ActualElemQuery elemQuery) {
        // TODO 气象要素统计
        List<ActualData> resultList = new ArrayList<ActualData>();
        List<msgmediumsmallscale> dataList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        String type = elemQuery.getType();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        List<String> countys = elemQuery.getCountys();
        List<String> stations = elemQuery.getStations();
        String rainFilter = elemQuery.getRainFilter();
        String stationid = elemQuery.getStationid();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observTime >='%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observTime <='%tF %tT'", endDate, endDate));
        }
        if (countys != null && countys.size() > 0) {
            strWhere.append(" and county in (");
            String tempString = "";
            for (String county : countys) {
                tempString += String.format("'%s',", county);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }

        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stationname");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("county");
        columns.add("longitude");
        columns.add("observtime");
        columns.add("latitude");
        if (element != null && element.equals("rain")) {
            // 雨量和统计
            if (type != null && type.equals("sum")) {
                columns.add("sum(rain) as rain");
                columns.add("sum(evaporation) as evaporation");
                selectRequest.setSort(new String[]{"rain desc"});
                if (!StringUtil.IsNullOrEmpty(rainFilter)) {
                    strWhere.append(String.format(" and rain >='%s'", rainFilter));
                } else {
                    strWhere.append(" and rain <> -65535");
                }
            }
            // 表格统计
            if (type != null && (type.equals("spline") || type.equals("column"))) {
                columns.add("to_char(observtime, 'yyyy-MM-dd HH24:MI:SS') as observtime");
                columns.add("rain");
                strWhere.append(" and rain <> -65535");
                selectRequest.setSort(new String[]{"observtime"});
            }
        }
        if (element != null && element.equals("evaporttranspiration")) {
            // 蒸发量和统计
            if (type != null && type.equals("sum")) {
                columns.add("sum(evaporation) as evaporation");
                columns.add("sum(rain) as rain");
                selectRequest.setSort(new String[]{"evaporation desc"});
                strWhere.append(" and evaporation <> -65535");
            }
            // 表格统计
            if (type != null && (type.equals("spline") || type.equals("column"))) {
                columns.add("to_char(observtime, 'yyyy-MM-dd HH24:MI:SS') as observtime");
                columns.add("rain");
                strWhere.append(" and rain <> -65535");
                selectRequest.setSort(new String[]{"observtime"});
            }
        }
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
//        strWhere.append(" group by stationid");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale"); //区域站
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        try {
            if (dataList.size() > 0) {
                for (msgmediumsmallscale data : dataList) {
                    ActualData actualData = new ActualData();
                    actualData.setStationId(data.getStationid().trim());
                    actualData.setStationName(data.getStationname().trim());
                    actualData.setStationName(data.getCounty().trim());
                    actualData.setLon(data.getLongitude());
                    actualData.setLat(data.getLatitude());
                    DmMapPoint dt = iTransformService.LonLatConvertToLambert(data.getLongitude(), data.getLatitude());
                    actualData.setX(dt.x);
                    actualData.setY(dt.y);
                    actualData.setRain(Double.parseDouble(String.format("%.1f", data.getRain())));
                    actualData.setEvaporation(Double.parseDouble(String.format("%.1f", data.getEvaporation())));
                    actualData.setDateTime(data.getObservtime());
                    resultList.add(actualData);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }


    @Override
    public List<warning> getWarningInfo(String startDate, String endDate, int id) {
        // TODO 预警信号表
        List<warning_area_bind> list = new ArrayList<warning_area_bind>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<warning> resultList = new ArrayList<warning>();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("Area");
        columns.add("Type");
        columns.add("Color");
        columns.add("County");
        columns.add("Standard");
        columns.add("DefenseGuide");
        columns.add("to_char(AnnouncedTime, 'yyyy-MM-dd HH24:MI:SS') as AnnouncedTime");
        columns.add("pos");
        columns.add("bFree");
        columns.add("y2path");
        columns.add("description");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(startDate)) {
            strWhere.append(String.format(" and AnnouncedTime>='%s'", startDate));
        }
        if (!StringUtil.IsNullOrEmpty(endDate)) {
            strWhere.append(String.format(" and AnnouncedTime<='%s'", endDate));
        }
        if (id > 0) {
            strWhere.append(String.format(" and id=%d", id));
        }
/*
        strWhere.append(" and city like '%" + DbConfig.CITY + "%' ");
*/
        strWhere.append(" and bfree=0");
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"AnnouncedTime desc"});
        try {
            selectParam.put("method", "warn_signal_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public thunder_fcst getLDNewDate() {
        // TODO 雷电最新时间
        thunder_fcst newDate = new thunder_fcst();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(reporttime, 'yyyy-MM-dd HH24:MI:SS') as reporttime",
                "forecasttime"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format(" city like '%s%%'", DbConfig.CITY));
        selectRequest.setSort(new String[]{"reporttime desc", "forecasttime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "thunder_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<thunder_fcst>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setReporttime(DateTime.now().toDate());
            Integer timechar = DateTime.now().GetHour() >= 8 && DateTime.now().GetHour() < 20 ? 8 : 20;
            newDate.setForecasttime(timechar.toString());
        }
        return newDate;
    }

    @Override
    public List<thunder_fcst> getThunderFcst(String time, String sc, String sx) {
        // TODO 雷电潜势预报查询
        List<thunder_fcst> resultList = new ArrayList<thunder_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(time)) {
            strWhere.append(String.format("to_char(reporttime, 'yyyy-MM-dd')='%s'", time));
        }
        if (!StringUtil.IsNullOrEmpty(sc)) {
            strWhere.append(String.format(" and forecasttime='%s'", sc));
        }
        if (!StringUtil.IsNullOrEmpty(sx)) {
            strWhere.append(String.format(" and forecastntimes='%s'", sx));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "thunder_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<thunder_fcst>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<warning> getWarningType(String startDate, String endDate) {
        // TODO 预警信号全部展示
        List<warning> resultList = new ArrayList<warning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"DISTINCT type", "color", "county"});
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(startDate)) {
            strWhere.append(String.format(" and AnnouncedTime>='%s'", startDate));
        }
        if (!StringUtil.IsNullOrEmpty(endDate)) {
            strWhere.append(String.format(" and AnnouncedTime<='%s'", endDate));
        }
        strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        strWhere.append(" and bfree=0");
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "warn_signal_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public String getQxWarnDoc(String docpath) {
        // TODO 获取气象预警文档
        List<base_product> listData = new ArrayList<base_product>();
        String result = "";
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(docpath)) {
            strWhere.append(String.format("productname='%s'", docpath));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (base_product dzWarn : listData) {
                result = dzWarn.getId().toString();
            }
        }
        return result;
    }

    @Override
    public shitai_text getZhiDaoNewDate() {
        // TODO 初始化指导预报
        shitai_text newDate = new shitai_text();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datetime, 'yyyy-MM-dd HH24:MI:SS') as datetime"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datetime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "shitai_text");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<shitai_text>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setDatetime(DateTime.now().toDate());
        }
        return newDate;
    }

    @Override
    public List<shitai_text> getZhiDaoInfo(String startDate, String endDate) {
        // TODO 指数预报查询
        List<shitai_text> resultList = new ArrayList<shitai_text>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(startDate)) {
            strWhere.append(String.format("datetime>='%s'", startDate));
        }
        if (!StringUtil.IsNullOrEmpty(endDate)) {
            strWhere.append(String.format(" and datetime<='%s'", endDate));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "shitai_text");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<shitai_text>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }


    @Override
    public List<smallscale_station> getStations(DmMapRectangle rect) {
        // TODO 获取区域站点
        List<smallscale_station> resultList = new ArrayList<smallscale_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (rect != null) {
            strWhere.append(String.format("longitude>='%s' and longitude<='%s' and  latitude>='%s' and  latitude<='%s' and county like '%s%%' ", rect.minX, rect.maxX, rect.minY, rect.maxY, DbConfig.COUNTY));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "smallscale_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<msgmediumsmallscale> getSKinfo(String startDate, String endDate, List<String> stationids) {
        // TODO 获取预警区内实况信息
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("sum(rain) as rain");
        columns.add("cast(avg(cast(DryBulbTemp as numeric(18,1))) as FLOAT) as DryBulbTemp");
        columns.add("avg(InstantWindV) as InstantWindV");
        columns.add("cast(avg(RelHumidity) as integer) as RelHumidity");
        columns.add("avg(StationPress) as StationPress");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(startDate)) {
            strWhere.append(String.format("observtime>='%s'", startDate));
        }
        if (!StringUtil.IsNullOrEmpty(endDate)) {
            strWhere.append(String.format(" and observtime<='%s'", endDate));
        }
        if (stationids != null && stationids.size() > 0) {
            strWhere.append(" and stationid in (");
            String tempString = "";
            for (String station : stationids) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"rain desc"});
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<township_station> getYBStations(DmMapRectangle rect) {
        // TODO 乡镇站点
        List<township_station> resultList = new ArrayList<township_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (rect != null) {
            strWhere.append(String.format("longitude>='%s' and longitude<='%s' and  latitude>='%s' and  latitude<='%s' and  city like '%s%%'", rect.minX, rect.maxX, rect.minY, rect.maxY, DbConfig.CITY));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "township_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_station>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<WeatherVo> getWeatherByCondition(List<String> countys, String startDate, String endDate) {
        //装载包含气象站id 气象站名 雨量数据对象的List容器
        List<WeatherVo> weatherVos = new ArrayList<>();
        List<adminCode> adminCodes = new ArrayList<>();
        //先查询water_rain表 获取气象站id和气象站名
        Map<String, String> selectParam = new HashMap<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        //查询county对应的addvcd
        StringBuilder commonCondition = new StringBuilder(" advname in (");
        for (int i = 0; i < countys.size(); i++) {
            commonCondition.append("'" + countys.get(i) + "'");
            if (i < countys.size() - 1) {
                commonCondition.append(",");
            }
        }
        commonCondition.append(")");


        selectRequest.setParam(commonCondition.toString());
        try {
            selectParam.put("method", "admin_code");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            adminCodes = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<adminCode>>() {
            });
            List<String> addvcds = new ArrayList<>();
            for (adminCode adminCode : adminCodes) {
                addvcds.add(adminCode.getAdvcode());
            }
            //查询water_station
            List<String> columns = new ArrayList<>();
            selectRequest = new RequestDataBySelect();
            columns.add("stcd as stationId");
            columns.add("stnm as stationname");
            columns.add("lgtd as lon");
            columns.add("lttd as lat");
            columns.add("addvcd");
            selectRequest.setColumns(columns.toArray(new String[]{}));
            StringBuilder strWhere = new StringBuilder(" addvcd in (");
            for (int i = 0; i < addvcds.size(); i++) {
                strWhere.append("'" + addvcds.get(i) + "'");
                if (i < addvcds.size() - 1) {
                    strWhere.append(",");
                }
            }
            strWhere.append(")");

            strWhere.append(" and stlc like '%" + DbConfig.STATIONNAME + "%' and (sttp = 'PP' or sttp = 'MM')");
            selectRequest.setParam(strWhere.toString());
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = pc.processRequest(selectParam);
            weatherVos = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<WeatherVo>>() {
            });

            List<String> stationids = new ArrayList<>();
            for (WeatherVo weatherVo : weatherVos) {
                stationids.add(weatherVo.getStationid());
                for (adminCode addvcd : adminCodes) {
                    if (weatherVo.getAddvcd().equals(addvcd.getAdvcode()))
                        weatherVo.setAddvcd(addvcd.getAdvname());
                }
            }
            selectRequest = new RequestDataBySelect();
            selectParam = new HashMap<>();
            columns = new ArrayList<>();
            columns.add("stcd as stationId");
            columns.add("drp as rain");
            selectRequest.setColumns(columns.toArray(new String[]{}));
            int whereCount = 0;
            if (stationids != null && stationids.size() > 0) {
                strWhere = new StringBuilder(" stcd in (");
                for (int i = 0; i < stationids.size(); i++) {
                    strWhere.append("'" + stationids.get(i) + "'");
                    if (i < stationids.size() - 1) {
                        strWhere.append(",");
                    }
                }
                strWhere.append(")");
                whereCount++;
            }
            if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                strWhere = strWhere.replace(0, 4, "");
            }
            strWhere.append(String.format(" and tm>='%s:00:00'", startDate));
            strWhere.append(String.format(" and tm<='%s:00:00'", endDate));
            selectRequest.setParam(strWhere.toString());
            selectParam.put("method", "water_rain");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = pc.processRequest(selectParam);
            List<WeatherVo> water_station = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<WeatherVo>>() {
            });
            //组合对象
            for (WeatherVo weather : weatherVos) {
                for (WeatherVo weather2 : water_station) {
                    if (weather.getStationid().equals(weather2.getStationid())) {
                        weather.setRain(weather2.getRain());
                        break;
                    }

                }
            }

        } catch (Exception e) {

        }
        return weatherVos;
    }

    /***
     * 得到最近站点未来三天天气预报
     * @param newestDate
     * @param lon
     * @param lat
     * @return
     */
    @Override
    public List<TownshipForecast> getNearStaThreeForecast(TownshipForecastKey newestDate, String lon, String lat) {
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"stationid"});
        selectRequest.setSort(new String[]{"(longitude - " + Double.parseDouble(lon) + ") * (longitude - " + Double.parseDouble(lon) + ") + (latitude - " + Double.parseDouble(lat) + ") * (latitude - " + Double.parseDouble(lat) + ")"});
        selectRequest.setLimit(1);
        String stationID = "";
        try {
            selectParam.put("method", "township_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<township_station> result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_station>>() {
            });
            if (result != null && result.size() > 0)
                stationID = result.get(0).getStationid();
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (StringUtil.IsNullOrEmpty(stationID))
            return resultList;
        selectParam = new HashMap<String, String>();
        selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("CAST(replace(cast(humid AS VARCHAR),'-65535','99999') as numeric(18,1)) as humid");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("weather1");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(stationID)) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", stationID));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() > 0) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", 72,
                    0));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and city like '%s%%' ", DbConfig.CITY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            if (DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast_province");
            } else {
                selectParam.put("method", "township_forecast_provincetemp");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    /***
     * 获得最近站点最新的实况信息
     * @param lon
     * @param lat
     * @return
     */
    @Override
    public String getStationid(String lon, String lat) {
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"stationid"});
        selectRequest.setSort(new String[]{"(longitude - " + Double.parseDouble(lon) + ") * (longitude - " + Double.parseDouble(lon) + ") + (latitude - " + Double.parseDouble(lat) + ") * (latitude - " + Double.parseDouble(lat) + ")"});
        selectRequest.setLimit(1);
        String stationID = "";
        try {
            selectParam.put("method", "smallscale_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<smallscale_station> result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
            });
            if (result != null && result.size() > 0)
                stationID = result.get(0).getStationid();
        } catch (Exception e) {
            // TODO: handle exception
        }
        return stationID;
    }

    /***
     * 获取水库或水电站坐标
     * @return
     */
    @Override
    public List<String> getReservoirLonlat(String staName) {
        List<String> result = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"lgtd", "lttd"});
        selectRequest.setParam("stnm='" + staName + "'");
        String stationID = "";
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<water_station> result1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            if (result1 != null && result1.size() > 0) {
                result.add(result1.get(0).getLgtd());
                result.add(result1.get(0).getLttd());
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    /***
     * 获取水库或水电站坐标
     * @return
     */
    @Override
    public List<String> getwatereleLonlat(String staName) {
        List<String> result = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"lon", "lat"});
        selectRequest.setParam("hydropowername='" + staName + "'");
        String stationID = "";
        try {
            selectParam.put("method", "hydropower_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<hydropower_info> result1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<hydropower_info>>() {
            });
            if (result1 != null && result1.size() > 0) {
                result.add(result1.get(0).getLon().toString());
                result.add(result1.get(0).getLat().toString());
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    /***
     *  初始化QPF
     * @return
     */
    @Override
    public List<String> initQpfPage(String ntimes) {
        List<String> result = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"datechar"});
        selectRequest.setParam("ntimes='090' and type = 'QPF'");
        selectRequest.setSort(new String[]{"datechar desc"});
        selectRequest.setLimit(3);
        try {
            selectParam.put("method", "qpe_qpf");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<qpe_qpf> result1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<qpe_qpf>>() {
            });
            if (result1 != null && result1.size() > 0) {
                for (qpe_qpf qpe : result1)
                    result.add(new DateTime(qpe.getDatechar()).toDateTimeString());
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    /****
     * 预报  七张图
     * @return
     */
    @Override
    public String getForecastTimeInfo() {
        return null;
    }

    @Override
    public List<township_forecasttemp> getYBinfo(List<String> stationids) {
        // TODO 预报信息
        TownshipForecastKey newDate = new TownshipForecastKey();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setParam(String.format(" 1=1 and city like '%s%%'", DbConfig.CITY));
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "township_forecast_province");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            if (!message.equals("[]")) {
                newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecastKey>>() {
                }).get(0);
            }
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setDateChar(DateTime.now().toDate());
            newDate.setNTimes(DateTime.now().GetHour() >= 8 && DateTime.now().GetHour() < 20 ? 8 : 20);
        }
        List<township_forecasttemp> resultList = new ArrayList<township_forecasttemp>();
        if (newDate.getTimeChar() != null) {
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            List<String> column = new ArrayList<String>();
            column.add("timechar");
            column.add("ntimes");
            column.add("stationid");
            column.add("StationName");
            column.add("longitude");
            column.add("latitude");
            column.add("CAST(replace(cast(humid AS VARCHAR),'-65535','99999') as numeric(18,1)) as humid");
            column.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
            column.add("NTimes");
            column.add("weather1");
            column.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
            column.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
            column.add("winds");
            column.add("windd");
            column.add("rain");
            selectRequest.setColumns(column.toArray(new String[column.size()]));
            // 拼接where字段
            StringBuilder strWhere = new StringBuilder();
            if (stationids != null && stationids.size() > 0) {
                strWhere.append(" and stationid in (");
                String tempString = "";
                for (String station : stationids) {
                    tempString += String.format("'%s',", station);
                }
                strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
            }
            if (newDate.getDateChar() != null) {
                strWhere.append(String.format(" and datechar='%tF'", newDate.getDateChar()));
            }
            if (!StringUtil.IsNullOrEmpty(newDate.getTimeChar())) {
                strWhere.append(String.format(" and timechar='%s'", newDate.getTimeChar()));
            }
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", 24, 0));
            if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
                strWhere = strWhere.replace(0, 4, "");
            }
            //strWhere.append(String.format(" and city like '%s%%' and areaname ='%s'", DbConfig.CITY, DbConfig.COUNTY));
            strWhere.append(String.format(" and city like '%s%%' ", DbConfig.CITY));
            selectRequest.setParam(strWhere.toString());
            selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
            try {
                if (DateTime.UserMainDataTable(newDate.getDateChar(), DbConfig.CACHEDAYS)) {
                    selectParam.put("method", "township_forecast_province");
                } else {
                    selectParam.put("method", "township_forecast_province");
                }
                selectParam.put("sqlType", "select");
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String message = pc.processRequest(selectParam);
                resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecasttemp>>() {
                });
            } catch (Exception e) {
                // TODO: handle exception
                System.err.println(e.getStackTrace());
            }
        }
        return resultList;
    }

    @Override
    public List<village> getCountryPoint(DmMapRectangle rect) {
        // TODO 村点
        List<village> resultList = new ArrayList<village>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (rect != null) {
            strWhere.append(String.format("lon>='%s' and lon<='%s' and  lat>='%s' and  lat<='%s'", rect.minX, rect.maxX, rect.minY, rect.maxY));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "village");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<village>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<base_product> showLDDoc(String cpName) {
        // TODO 雷电潜势预报文档
        List<base_product> listData = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(cpName)) {
            strWhere.append(String.format(" and productname='%s'", cpName));
        }
        strWhere.append(String.format(" and producttype='%s'", "潜势预报"));
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<township_forecasttemp> getCityStation() {
        // TODO 获取乡镇区县字段
        List<township_forecasttemp> listData = new ArrayList<township_forecasttemp>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"DISTINCT areaname"};
        selectRequest.setColumns(columns);
        try {
            selectParam.put("method", "township_forecast_province");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecasttemp>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public base_product initWdPage() {
        // TODO 雷电文档
        base_product newDate = new base_product();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(forecasttime, 'yyyy-MM-dd HH24:MI:SS') as forecasttime"};
        selectRequest.setColumns(columns);
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format(" and producttype='%s'", "潜势预报"));
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"forecasttime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setForecasttime(DateTime.now().toDate());
        }
        return newDate;
    }

    @Override
    public List<base_product> getLdWord(String startDate, String endDate) {
        // TODO 雷电潜势文档
        List<base_product> listData = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(startDate)) {
            strWhere.append(String.format(" and forecasttime>='%s'", startDate + " 00:00:00"));
        }
        if (!StringUtil.IsNullOrEmpty(endDate)) {
            strWhere.append(String.format(" and forecasttime<='%s'", endDate + " 23:59:59"));
        }
        strWhere.append(String.format(" and producttype='%s'", "潜势预报"));
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<warning> getWarnInfo() {
        // TODO Auto-generated method stub
        List<warning> resultList = new ArrayList<warning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"area", "type", "color", "standard", "AnnouncedTime"});
        DateTime dt = DateTime.now();
        String date = dt.AddDays(-1).toDateTimeString(); // 开始时间
        String date1 = dt.toDateTimeString(); // 开始时间
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(date)) {
            strWhere.append(String.format(" and AnnouncedTime>='%s'", date));
        }
        if (!StringUtil.IsNullOrEmpty(date1)) {
            strWhere.append(String.format(" and AnnouncedTime<='%s'", date1));
        }
        strWhere.append(" and bfree=0");
        strWhere.append(" and city like '%" + DbConfig.CITY + "%'");
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
//        selectRequest.setLimit(1);
        selectRequest.setSort(new String[]{"announcedtime desc"});
        try {
            selectParam.put("method", "warn_signal_info");
            selectParam.put("sqlType", "select");
//            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<ForecastInfo> getThreeDayCityFcst(TownshipForecastKey newestDate) {
        // TODO 获取三天城市预报
        List<ForecastInfo> resultList = new ArrayList<ForecastInfo>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("(cast(datechar as timestamp)+ cast(ntimes||'hour' as INTERVAL)) as datechar");
        columns.add("NTimes");
        columns.add("weather1");
        columns.add("weather2");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("wind1");
        columns.add("wind2");
        columns.add("windd1");
        columns.add("windd2");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(newestDate.getStationID())) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", newestDate.getStationID()));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() == 168) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", 168,
                    0));
        } else {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", 72,
                    0));
        }
        //strWhere.append(String.format(" and stationname='"+DbConfig.STATIONNAME+"'"));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(
                String.format(" AND stationid = '%s' AND city LIKE '%s%%'", DbConfig.STATIONID, DbConfig.CITY));



        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar asc", "StationID ASC", "NTimes ASC"});
        try {
            if (DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "forecastinfo");
            } else {
                selectParam.put("method", "forecastinfo");
            }
            selectParam.put("sqlType", "select");

            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ForecastInfo>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public Doppler getRadarMosaicNewestDate() {
        // TODO 获取雷达图最新时间
        // DbContextHolder.setDbType("qx");
        // return forecastInfoDao.getRadarNewestDate();
        Doppler result = new Doppler();
        doppler newDate = new doppler();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "zwdoppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setDatechar(DateTime.now().toDate());
        }
        if (newDate != null) {
            result.setDateChar(newDate.getDatechar());
            result.setTimeChar(newDate.getTimechar());
        }
        return result;
    }

    @Override
    public List<Doppler> getRadarMosaicTypes() {
        // TODO 获取雷达图参数
        // DbContextHolder.setDbType("qx");
        // return forecastInfoDao.getRadarTypes();
        List<doppler> listData = new ArrayList<doppler>();
        List<Doppler> resultList = new ArrayList<Doppler>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"distinct ldtype"};
        selectRequest.setColumns(columns);
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        // strWhere.append(String.format(" and ldtype='%s'", 37));
        // strWhere.append(String.format(" or ldtype='%s'", 38));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "zwdoppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (doppler dop : listData) {
                Doppler dopplerKey = new Doppler();
                dopplerKey.setElevation(dop.getElevation());
                dopplerKey.setStationId(dop.getStationid());
                dopplerKey.setType(dop.getLdtype());
                resultList.add(dopplerKey);
            }
        }
        return resultList;
    }


    @Override
    public List<Doppler> getRadarMosaicInfo(RadarSearch radarSearch) {
        // TODO 获取雷达图信息
        /*
         * DbContextHolder.setDbType("qx"); return
         * forecastInfoDao.getRadarInfo(radarSearch);
         */
        List<doppler> listData = new ArrayList<doppler>();
        List<Doppler> resultList = new ArrayList<Doppler>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("TimeChar");
        columns.add("StationId");
        columns.add("LdType");
        columns.add("Elevation");
        columns.add("Path");
        columns.add("jwImgPath");
        columns.add("RadTitle");
        columns.add("fwest");
        columns.add("fsouth");
        columns.add("feast");
        columns.add("fnorth");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (radarSearch.getDataYear() != null) {
            strWhere.append(String.format("dataYear='%d'", radarSearch.getDataYear()));
            whereCount++;
        }
        if (radarSearch.getDateChar() != null) {
            strWhere.append(String.format(" and dateChar='%tF'", radarSearch.getDateChar()));
        }
        if (radarSearch.getStartDate() != null) {
            strWhere.append(String.format(
                    " and (cast(datechar as timestamp)+ CAST(SUBSTRING(TimeChar,1,2)||'hour' as INTERVAL))>='%s'",
                    radarSearch.getStartDate()));
        }
        if (radarSearch.getEndDate() != null) {
            strWhere.append(String.format(
                    " and (cast(datechar as timestamp)+ CAST(SUBSTRING(TimeChar,1,2)||'hour' as INTERVAL))<'%s'",
                    radarSearch.getEndDate()));
        }
        if (!StringUtil.IsNullOrEmpty(radarSearch.getTimeChar())) {
            strWhere.append(String.format(" and timeChar='%s'", radarSearch.getTimeChar()));
        }
        if (!StringUtil.IsNullOrEmpty(radarSearch.getStationId())) {
            strWhere.append(String.format(" and stationId='%s'", radarSearch.getStationId()));
        }
        if (!StringUtil.IsNullOrEmpty(radarSearch.getType())) {
            strWhere.append(String.format(" and ldtype='%s'", radarSearch.getType()));
        }
        if (radarSearch.getElevation() != null) {
            strWhere.append(String.format(" and elevation='%f'", radarSearch.getElevation()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "zwdoppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (doppler dop : listData) {
                Doppler doppler = new Doppler();
                doppler.setDateChar(dop.getDatechar());
                doppler.setTimeChar(dop.getTimechar());
                doppler.setStationId(dop.getStationid());
                doppler.setType(dop.getLdtype());
                doppler.setElevation(dop.getElevation());
                doppler.setPath(dop.getPath());
                doppler.setJwImgPath(dop.getJwimgpath());
                doppler.setRadTitle(dop.getRadtitle());
                doppler.setFxmin(dop.getFwest());
                doppler.setFxmax(dop.getFeast());
                doppler.setFymin(dop.getFsouth());
                doppler.setFymax(dop.getFnorth());
                resultList.add(doppler);
            }
        }
        return resultList;
    }

    @Override
    public List<warning> getFiveNewestWarning(int id) {
        List<warning> resultList = new ArrayList<warning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("Area");
        columns.add("Type");
        columns.add("Color");
        columns.add("County");
        columns.add("Standard");
        columns.add("DefenseGuide");
        columns.add("to_char(AnnouncedTime, 'yyyy-MM-dd HH24:MI:SS') as AnnouncedTime");
        columns.add("pos");
        columns.add("bFree");
        columns.add("y2path");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(" and description like '%" + DbConfig.CITY + "%'");
        if (id > 0) {
            strWhere.append(String.format(" and id=%d", id));
        }
        strWhere.append(" and bfree=0");
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"AnnouncedTime desc"});
        selectRequest.setLimit(5);
        try {
            selectParam.put("method", "warn_signal_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public raidentemp getLDDate() {
        raidentemp newDate = new raidentemp();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(observetime, 'yyyy-MM-dd HH24:MI:SS') as observetime",};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"observetime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "raiden");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<raidentemp>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return newDate;
    }

    @Override
    public Date getScaleDate() {
        Date date = new Date();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(observtime, 'yyyy-MM-dd HH24:MI:SS') as observtime"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("city like '%s%%' and county like '%s%%'", DbConfig.CITY, DbConfig.CITY));
        selectRequest.setSort(new String[]{"observtime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            date = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            }).get(0).getObservtime();
        } catch (Exception e) {
            // TODO: handle exception
        }
        return date;
    }

    @Override
    public List<ActualData> qxEltQuery(ActualElemQuery elemQuery) {
        List<ActualData> resultList = new ArrayList<>();
        List<MsgMediumSmallScale> dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        String type = elemQuery.getType();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        List<String> countys = elemQuery.getCountys();
        List<String> stations = elemQuery.getStations();
        String stationid = elemQuery.getStationid();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observTime >='%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observTime <='%tF %tT'", endDate, endDate));
        }
        if (countys != null && countys.size() > 0) {
            strWhere.append(" and city like '%");
            String tempString = "";
            for (String county : countys) {
                tempString += String.format("%s,", county);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + "%'");
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (stationid != null && stationid.length() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            tempString += String.format("'%s',", stationid);
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        if (element != null && element.equals("rain")) {
            // 雨量和统计
            if (type != null && type.equals("sum")) {
                columns.add("sum(rain) as rain");
                selectRequest.setSort(new String[]{"rain desc"});
                strWhere.append(" and rain <> -65535");
            }
            // 表格统计
            if (type != null && (type.equals("spline") || type.equals("column"))) {
                if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                    columns.add("to_char(observtime,'yyyy-MM-dd') as datechar");
                    columns.add("sum(rain) as rain");
                    strWhere.append(" and rain <> -65535");
                    selectRequest.setSort(new String[]{"to_char(observtime,'yyyy-MM-dd')"});
                } else {
                    columns.add("observtime");
                    columns.add("rain");
                    strWhere.append(" and rain <> -65535");
                    selectRequest.setSort(new String[]{"observtime"});
                }
            }
        }
        if (element != null && element.equals("temp")) {
            // 温度统计
            if (type != null && type.equals("sum") || type.equals("avg") || type.equals("min") || type.equals("max")) {
                columns.add("cast(" + type + "(cast(DryBulbTemp as numeric(18,1))) as FLOAT) as DryBulbTemp");
                strWhere.append(" and DryBulbTemp <> -65535");
                selectRequest.setSort(new String[]{"DryBulbTemp desc"});
            }
            // 表格统计
            if (type != null && (type.equals("spline") || type.equals("column"))) {
                if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                    columns.add("to_char(observtime,'yyyy-MM-dd') as datechar");
                    columns.add("avg(DryBulbTemp) as DryBulbTemp");
                    strWhere.append(" and DryBulbTemp <> -65535");
                    selectRequest.setSort(new String[]{"to_char(observtime,'yyyy-MM-dd')"});
                } else {
                    columns.add("observtime");
                    columns.add("DryBulbTemp");
                    strWhere.append(" and DryBulbTemp <> -65535");
                    selectRequest.setSort(new String[]{"observtime"});
                }
            }
        }
        if (element != null && element.equals("winds")) {
            // 风速统计
            if (type != null && type.equals("sum") || type.equals("avg") || type.equals("min") || type.equals("max")) {
                columns.add(type + "(InstantWindV) as InstantWindV");
                columns.add("instantwindd");
                strWhere.append(" and InstantWindV <> -65535");
                strWhere.append(" and instantwindd <> -65535");
                selectRequest.setSort(new String[]{"InstantWindV desc"});
            }
            // 表格统计
            if (type != null && (type.equals("spline") || type.equals("column"))) {
                if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                    columns.add("to_char(observtime,'yyyy-MM-dd') as datechar");
                    columns.add("avg(InstantWindV) as InstantWindV");
//                    columns.add("instantwindd");
                    strWhere.append(" and InstantWindV <> -65535");
//                    strWhere.append(" and instantwindd <> -65535");
                    selectRequest.setSort(new String[]{"to_char(observtime,'yyyy-MM-dd')"});
                } else {
                    columns.add("observtime");
                    columns.add("InstantWindV");
//                    columns.add("instantwindd");
                    strWhere.append(" and InstantWindV <> -65535");
//                    strWhere.append(" and instantwindd <> -65535");
                    selectRequest.setSort(new String[]{"observtime"});
                }
            }
        }
        if (element != null && element.equals("humid")) {
            // 湿度统计
            if (type != null && type.equals("sum") || type.equals("avg") || type.equals("min") || type.equals("max")) {
                columns.add("cast(" + type + "(RelHumidity) as integer) as RelHumidity");
                strWhere.append(" and RelHumidity <> -65535");
                selectRequest.setSort(new String[]{"RelHumidity desc"});
            }
            // 表格统计
            if (type != null && (type.equals("spline") || type.equals("column"))) {
                if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                    columns.add("to_char(observtime,'yyyy-MM-dd') as datechar");
                    columns.add("cast(avg(RelHumidity)as integer) as RelHumidity");
                    strWhere.append(" and RelHumidity <> -65535");
                    selectRequest.setSort(new String[]{"to_char(observtime,'yyyy-MM-dd')"});
                } else {
                    columns.add("observtime");
                    columns.add("RelHumidity");
                    strWhere.append(" and RelHumidity <> -65535");
                    selectRequest.setSort(new String[]{"observtime"});
                }
            }
        }
        if (element != null && element.equals("pressure")) {
            // 气压统计
            if (type != null && type.equals("sum") || type.equals("avg") || type.equals("min") || type.equals("max")) {
                columns.add(type + "(StationPress) as StationPress");
                strWhere.append(" and StationPress <> -65535");
                selectRequest.setSort(new String[]{"StationPress desc"});
            }
            // 表格统计
            if (type != null && (type.equals("spline") || type.equals("column"))) {
                if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                    columns.add("to_char(observtime,'yyyy-MM-dd') as datechar");
                    columns.add("avg(StationPress) as StationPress");
                    strWhere.append(" and StationPress <> -65535");
                    selectRequest.setSort(new String[]{"to_char(observtime,'yyyy-MM-dd')"});
                } else {
                    columns.add("observtime");
                    columns.add("StationPress");
                    strWhere.append(" and StationPress <> -65535");
                    selectRequest.setSort(new String[]{"observtime"});
                }
            }
        }
        if (element != null && element.equals("visibility")) {
            // 能见度统计
            if (type != null && type.equals("sum") || type.equals("avg") || type.equals("min") || type.equals("max")) {
                columns.add(type + "(visibility) as visibility");
                strWhere.append(" and visibility <> -65535");
                selectRequest.setSort(new String[]{"visibility asc"});
            }
            // 表格统计
            if (type != null && (type.equals("spline") || type.equals("column"))) {
                if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                    columns.add("to_char(observtime,'yyyy-MM-dd') as datechar");
                    columns.add("avg(visibility) as visibility");
                    strWhere.append(" and visibility <> -65535");
                    selectRequest.setSort(new String[]{"to_char(observtime,'yyyy-MM-dd')"});
                } else {
                    columns.add("observtime");
                    columns.add("visibility");
                    strWhere.append(" and visibility <> -65535");
                    selectRequest.setSort(new String[]{"observtime"});
                }
            }
        }
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            if (DateTime.UserMainDataTable(elemQuery.getStartDate(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "msgmediumsmallscale");
            } else {
                selectParam.put("method", "msgmediumsmallscale");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<MsgMediumSmallScale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        try {
            WebCtrlData webCtrlData = new WebCtrlData();
            if (dataList.size() > 0) {
                for (MsgMediumSmallScale data : dataList) {
                    ActualData actualData = new ActualData();
                    actualData.setStationId(data.getStationid().trim());
                    actualData.setStationName(data.getStationname().trim());
                    actualData.setLon(data.getLongitude());
                    actualData.setLat(data.getLatitude());
                    DmMapPoint dt = iTransformService.LonLatConvertToLambert(data.getLongitude(), data.getLatitude());
                    actualData.setX(dt.x);
                    actualData.setY(dt.y);
                    switch (element) {
                        case "rain":
                            actualData.setRain(Double.parseDouble(String.format("%.1f", data.getRain())));
                            break;
                        case "temp":
                            actualData.setTemp(Double.parseDouble(String.format("%.1f", data.getDrybulbtemp())));
                            break;
                        case "humid":
                            actualData.setHumid(Double.parseDouble(String.format("%d", data.getRelhumidity())));
                            break;
                        case "winds":
                            actualData.setWinds(Double.parseDouble(String.format("%.1f", data.getInstantwindv())));
                            if (type != null && type.equals("sum") || type.equals("avg") || type.equals("min") || type.equals("max")) {
                                String s = webCtrlData.GetAllFx(data.getInstantwindd().toString());
                                actualData.setWinddirect(s);
                                int i = webCtrlData.FengSuToFengJi(data.getInstantwindv());
                                actualData.setWindvelocity(i);
                            }
                            break;
                        case "pressure":
                            actualData.setPressure(Double.parseDouble(String.format("%.1f", data.getStationpress())));
                            break;
                        case "visibility":
                            actualData.setVisibility(data.getVisibility());
                            break;
                        default:
                            break;
                    }
                    if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        actualData.setDateTime(sdf.parse(data.getDatechar()));
//                        actualData.setDateTime(data.getObservTime());
                    } else {
                        actualData.setDateTime(data.getObservTime());
                    }
                    resultList.add(actualData);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    /***
     * 获取雷达图   最新十张
     * @param request
     * @return
     */
    @Override
    public Object GetTenDoppler(HttpServletRequest request) {
        String result = "";
        List<doppler> infos = new ArrayList<doppler>();
        String drainagearea = request.getParameter("drainagearea");
        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("1=1  and 2=2 and 3=3  and state=1");
        dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "ldType ='CR37'"));
        dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "StationId ='" + DbConfig.radarid + "'"));//后续需要改qxy
        dataBySelect.setParam(dataBySelect.getParam().replace("3=3", "Elevation ='0'"));
        dataBySelect.setSort(new String[]{"DateChar desc,TimeChar desc"});
        dataBySelect.setLimit(10);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "doppler");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<doppler>>() {
                });
                for (doppler sl : infos) {
                    String fileName = "ld_jpg_sl_file" + "_" + new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd") + "_" + sl.getTimechar().trim() + "_19_0.5_" + drainagearea;
                    String serviceFilePath = "";
                    String timechar = sl.getTimechar();
                    String hour = timechar.substring(0, 2);
                    String min = timechar.substring(timechar.length() - 2, timechar.length());
                    String datechar = new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd");
                    datechar = datechar + " " + hour + ":" + min + ":" + "00";
                    // 下载
                    fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path
                            + "/Temp/Leida/";
                    String serviceUrl = basePath + fileName;
                    String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Leida\\";
                    serviceFilePath = urlpath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器
                        Map<String, Object> queryMap = new HashMap<String, Object>();
                        queryMap.put("datetime", datechar);
                        queryMap.put("drainagearea", drainagearea);
                        queryMap.put("advCode", DbConfig.advCode);
                        queryMap.put("collectionName", "ld_s_jpg_sl_file");
                        byte[] data = ms.selectData(queryMap);
                        if (data == null) {
                            serviceFilePath = "";
                        } else {
                            FileUtil.bytesToFile(data, serviceFilePath);
                        }
                    }
                    if (!serviceFilePath.equals("")) {
                        serviceFilePath = serviceUrl;
                    }

                    String imagepath = serviceFilePath;
                    sl.setJwimgpath(imagepath);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    // 初始化水库流量信息
    @Override
    public List<water_station> getShuiKuInfo() {
        // TODO 获取水库流量预报最新时间
        List<water_station> types = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("lgtd");
        columns.add("lttd");
        columns.add("stlc");
        columns.add("dtrange");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            types = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return types;
    }

    /**
     * 采集时间
     *
     * @param type 类型
     * @return
     */
    @Override
    public Object getCollectTimeByType(String type) {
        List<collectTime> collectTimeList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"type", "year", "month", "day", "hour", "minute", "second"};
        selectRequest.setColumns(columns);
        if (!StringUtil.IsNullOrEmpty(type)) {
            selectRequest.setParam(String.format("type = '%s'", type));
        }
        try {
            selectParam.put("method", "collect_time");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            collectTimeList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<collectTime>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", collectTimeList, true);
    }

    /**
     * 采集日志
     *
     * @param type 类型
     * @return
     */
    @Override
    public Object getCollectLogByTimeNType(Date startDate, Date endDate, String type) {
        List<collectLogMonitor> collectLog = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(monitortime, 'yyyy-MM-dd HH24:MI:SS') as monitortime",
                "to_char(datatime, 'yyyy-MM-dd HH24:MI:SS') as datatime", "id", "type",
                "name", "content", "state", "remark"};
        selectRequest.setColumns(columns);
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("monitortime >= '%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and monitortime <= '%tF %tT'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(type)) {
            strWhere.append(String.format(" and type = '%s'", type));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "collect_log_monitor");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            collectLog = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<collectLogMonitor>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", collectLog, true);
    }

    /**
     * 等级分级
     *
     * @param elementType
     * @return
     */
    @Override
    public Object getContourSettingByType(String elementType) {
        List<contour_setting> contourList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        if (!StringUtil.IsNullOrEmpty(elementType)) {
            selectRequest.setParam(String.format("elementtype = '%s'", elementType));
        }
        try {
            selectParam.put("method", "contour_setting");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            contourList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<contour_setting>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", contourList, true);
    }

    /**
     * 干旱检测
     *
     * @param startDate
     * @param endDate
     * @param stationid
     * @return
     */
    @Override
    public Object getDroughtCIByTime(Date startDate, Date endDate, String stationid) {
        List<drought> droughtList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observationdate >= '%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observationdate <= '%tF %tT'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(stationid)) {
            strWhere.append(String.format(" and stationid = '%s'", stationid));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "drought");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            droughtList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<drought>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", droughtList, true);
    }

    /**
     * 城镇预报
     *
     * @param forecastInfo
     * @return
     */
    @Override
    public List<ForecastInfo> getCityForecastByTimeNArea(ForecastInfo forecastInfo) {
        List<ForecastInfo> forecastInfoList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("weather1");
        columns.add("weather2");
        columns.add("wind1");
        columns.add("wind2");
        columns.add("windd1");
        columns.add("windd2");
        columns.add("city");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (forecastInfo.getDatechar() != null) {
            whereCount++;
            strWhere.append(String.format("datechar = '%tF %tT'", forecastInfo.getDatechar(), forecastInfo.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(forecastInfo.getTimechar())) {
            strWhere.append(String.format(" and timechar = '%s'", forecastInfo.getTimechar()));
        }
        if (!StringUtil.IsNullOrEmpty(forecastInfo.getCity())) {
            strWhere.append(String.format(" and city = '%s'", forecastInfo.getCity()));
        }
        if (!StringUtil.IsNullOrEmpty(forecastInfo.getStationid())) {
            strWhere.append(String.format(" and stationid = '%s'", forecastInfo.getStationid()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "forecastinfotemp");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            forecastInfoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ForecastInfo>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return forecastInfoList;
    }

    /**
     * 全国城镇预报
     *
     * @param forecastInfo
     * @return
     */
    @Override
    public List<ForecastInfo> getCountryCityForecastByTimeNArea(ForecastInfo forecastInfo) {
        List<ForecastInfo> forecastInfoList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("weather1");
        columns.add("weather2");
        columns.add("wind1");
        columns.add("wind2");
        columns.add("windd1");
        columns.add("windd2");
        columns.add("city");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (forecastInfo.getDatechar() != null) {
            whereCount++;
            strWhere.append(String.format("datechar = '%tF %tT'", forecastInfo.getDatechar(), forecastInfo.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(forecastInfo.getTimechar())) {
            strWhere.append(String.format(" and timechar = '%s'", forecastInfo.getTimechar()));
        }
        if (!StringUtil.IsNullOrEmpty(forecastInfo.getCity())) {
            strWhere.append(String.format(" and city = '%s'", forecastInfo.getCity()));
        }
        if (!StringUtil.IsNullOrEmpty(forecastInfo.getCounty())) {
            strWhere.append(String.format(" and county = '%s'", forecastInfo.getCounty()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "forecastinfotemp");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            forecastInfoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ForecastInfo>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return forecastInfoList;
    }

    /**
     * 自动站
     *
     * @return
     */
    @Override
    public Object getSmallScaleByTimeNArea(ActualElemQuery elemQuery) {
        //返回：站号、站名、市、县、要素值
        List<msgmediumsmallscale> msgmediumsmallscales = new ArrayList<>();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        String city = elemQuery.getCity();
        String county = elemQuery.getCounty();
        //要素
        List<String> elements = elemQuery.getElements();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("city");
        columns.add("county");
        //要素
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observtime >= '%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observtime <= '%tF %tT'", endDate, endDate));
        }
        /*if (!StringUtil.IsNullOrEmpty(city)) {
            strWhere.append(String.format(" and city = '%s'", city));
        }*/
        if (!StringUtil.IsNullOrEmpty(county)) {
            strWhere.append(String.format(" and county = '%s'", county));
        }
        if (elements != null && elements.size() > 0) {
            for (String element : elements) {
                if (element != null && element.equals("rain")) {
                    // 雨量
                    columns.add("sum(rain) as rain");
                    selectRequest.setSort(new String[]{"rain desc"});
                    strWhere.append(" and rain <> -65535");

                }
                if (element != null && element.equals("temp")) {
                    // 温度
                    columns.add("cast(" + "(cast(DryBulbTemp as numeric(18,1))) as FLOAT) as DryBulbTemp");
                    strWhere.append(" and DryBulbTemp <> -65535");
                    selectRequest.setSort(new String[]{"DryBulbTemp desc"});

                }
                if (element != null && element.equals("winds")) {
                    // 风速统计
                    columns.add("(InstantWindV) as InstantWindV");
                    columns.add("instantwindd");
                    strWhere.append(" and InstantWindV <> -65535");
                    strWhere.append(" and instantwindd <> -65535");
                    selectRequest.setSort(new String[]{"InstantWindV desc"});
                }
                if (element != null && element.equals("humid")) {
                    // 湿度
                    columns.add("cast(" + "(RelHumidity) as integer) as RelHumidity");
                    strWhere.append(" and RelHumidity <> -65535");
                    selectRequest.setSort(new String[]{"RelHumidity desc"});
                }
                if (element != null && element.equals("pressure")) {
                    // 气压
                    columns.add("stationPress");
                    strWhere.append(" and stationPress <> -65535");
                    selectRequest.setSort(new String[]{"StationPress desc"});
                }
                if (element != null && element.equals("visibility")) {
                    // 能见度
                    columns.add("visibility");
                    strWhere.append(" and visibility <> -65535");
                    selectRequest.setSort(new String[]{"visibility asc"});
                }
            }
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            msgmediumsmallscales = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", msgmediumsmallscales, true);
    }

    @Override
    public Object getSmallScaleByTimeNStationIds(ActualElemQuery elemQuery) {
        //返回：站号、站名、市、县、要素值
        List<msgmediumsmallscale> msgmediumsmallscales = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        List<String> stations = elemQuery.getStations();
        List<String> elements = elemQuery.getElements();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("city");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observtime >= '%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observtime <= '%tF %tT'", endDate, endDate));
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationid in (");
            String tempString = "";
            for (String stationid : stations) {
                tempString += String.format("'%s',", stationid);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (elements != null && elements.size() > 0) {
            for (String element : elements) {
                if (element != null && element.equals("rain")) {
                    // 雨量统计
                    columns.add("sum(rain) as rain");
                    selectRequest.setSort(new String[]{"rain desc"});
                    strWhere.append(" and rain <> -65535");
                }
                if (element != null && element.equals("temp")) {
                    // 温度统计
                    columns.add("cast(" + "(cast(DryBulbTemp as numeric(18,1))) as FLOAT) as DryBulbTemp");
                    strWhere.append(" and DryBulbTemp <> -65535");
                    selectRequest.setSort(new String[]{"DryBulbTemp desc"});
                }
                if (element != null && element.equals("winds")) {
                    // 风速统计
                    columns.add("(InstantWindV) as InstantWindV");
                    columns.add("instantwindd");
                    strWhere.append(" and InstantWindV <> -65535");
                    strWhere.append(" and instantwindd <> -65535");
                    selectRequest.setSort(new String[]{"InstantWindV desc"});
                }
                if (element != null && element.equals("humid")) {
                    // 湿度统计
                    columns.add("cast(" + "(RelHumidity) as integer) as RelHumidity");
                    strWhere.append(" and RelHumidity <> -65535");
                    selectRequest.setSort(new String[]{"RelHumidity desc"});
                }
                if (element != null && element.equals("pressure")) {
                    // 气压统计
                    columns.add("stationPress");
                    strWhere.append(" and stationPress <> -65535");
                    selectRequest.setSort(new String[]{"StationPress desc"});
                }
                if (element != null && element.equals("visibility")) {
                    // 能见度统计
                    columns.add("visibility");
                    strWhere.append(" and visibility <> -65535");
                    selectRequest.setSort(new String[]{"visibility asc"});
                }
            }
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            msgmediumsmallscales = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", msgmediumsmallscales, true);
    }

    /**
     * 闪电定位
     *
     * @param elemQuery
     * @return
     */
    @Override
    public Object getRaidenByTimeNArea(ActualElemQuery elemQuery) {
        List<raiden> raidenList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        String city = elemQuery.getCity();
        String county = elemQuery.getCounty();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observetime >= '%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observetime <= '%tF %tT'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(city)) {
            strWhere.append(String.format(" and city = '%s'", city));
        }
        if (!StringUtil.IsNullOrEmpty(county)) {
            strWhere.append(String.format(" and county = '%s'", county));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "raiden");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            raidenList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<raiden>>() {
            });
        } catch (Exception e) {
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", raidenList, true);
    }

    @Override
    public Object getRaidenByTimeNLonLat(ActualElemQuery elemQuery) {
        List<raiden> raidenList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        Float lon = elemQuery.getLon();
        Float lat = elemQuery.getLat();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observetime >= '%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observetime <= '%tF %tT'", endDate, endDate));
        }
        if (lon != null) {
            strWhere.append(String.format(" and lon = '%f'", lon));
        }
        if (lat != null) {
            strWhere.append(String.format(" and lat = '%f'", lat));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "raiden");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            raidenList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<raiden>>() {
            });
        } catch (Exception e) {
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", raidenList, true);
    }

    @Override
    public Object getReservoirWaterInfoByTimeNArea(Date startDate, Date endDate, reservoirWaterInfo reservoirWaterInfo) {
        List<reservoirWaterInfo> waterInfoList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String city = reservoirWaterInfo.getCity();
        String county = reservoirWaterInfo.getCounty();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observtime >= '%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observtime <= '%tF %tT'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(city)) {
            strWhere.append(String.format(" and city = '%s'", city));
        }
        if (!StringUtil.IsNullOrEmpty(county)) {
            strWhere.append(String.format(" and county = '%s'", county));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "reservoir_water_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            waterInfoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoirWaterInfo>>() {
            });
        } catch (Exception e) {
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", waterInfoList, true);
    }

    @Override
    public Object getReservoirWaterInfoByTimeNStationIds(ActualElemQuery actualElemQuery) {
        List<reservoirWaterInfo> waterInfoList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Date observetime = actualElemQuery.getStartDate();
        List<String> stations = actualElemQuery.getStations();
        Date startDate = actualElemQuery.getStartDate();
        Date endDate = actualElemQuery.getEndDate();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observtime >= '%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observtime <= '%tF %tT'", endDate, endDate));
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationid in (");
            String tempString = "";
            for (String stationid : stations) {
                tempString += String.format("'%s',", stationid);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "reservoir_water_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            waterInfoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoirWaterInfo>>() {
            });
        } catch (Exception e) {
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", waterInfoList, true);
    }

    /**
     * 河道水情
     *
     * @param addvcd
     * @return
     */
    @Override
    public Object getRiverWaterInfoByTimeNArea(Date startDate, Date endDate, String addvcd) {
        List<water_station> dataList = new ArrayList<water_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        selectRequest.setParam(String.format("addvcd ='%s'", addvcd));
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            if (dataList != null && dataList.size() > 0) {
                for (water_station w : dataList) {
                    List<water> dataList1 = new ArrayList<water>();
                    selectParam = new HashMap<String, String>();
                    selectRequest = new RequestDataBySelect();
                    // 获取查询字段
                    StringBuilder strWhere = new StringBuilder();
                    int whereCount = 0;
                    if (startDate != null) {
                        whereCount++;
                        strWhere.append(String.format("latestobservetime >= '%tF %tT'", startDate, startDate));
                    }
                    if (endDate != null) {
                        strWhere.append(String.format(" and latestobservetime <= '%tF %tT'", endDate, endDate));
                    }
                    if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                        strWhere = strWhere.replace(0, 4, "");
                    }
                    selectRequest.setParam(strWhere.toString());
                    try {
                        selectParam.put("method", "water");
                        selectParam.put("sqlType", "select");
                        selectParam.put("param", JsonUtil.object2Json(selectRequest));
                        message = pc.processRequest(selectParam);
                        dataList1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
                        });
                        if (dataList1 != null && dataList1.size() > 0) {
                            for (water sta : dataList1) {
                                if (w.getStcd().equals(sta.getStationid())) {
                                    w.setStnm(w.getStnm().trim());
                                    w.setLon(w.getLgtd());
                                    w.setLat(w.getLttd());
                                    w.setTime(new DateTime(sta.getLatestobservetime()).toDateTimeString());
                                    w.setStationid(sta.getStationid());
                                    w.setBsnm(sta.getSmallscalewaterstatus().toString());
                                }

                            }
                        }
                    } catch (Exception e) {
                        // TODO: handle exception
                        System.err.println(e.getStackTrace());
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    @Override
    public Object getRiverWaterInfoByTimeNStationIds(Date startDate, Date endDate, String[] stations) {
        List<water_station> dataList = new ArrayList<water_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        StringBuilder strWhere = new StringBuilder();
        if (stations != null && stations.length > 0) {
            strWhere.append(" stcd in (");
            String tempString = "";
            for (String stationid : stations) {
                tempString += String.format("'%s',", stationid);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            if (dataList != null && dataList.size() > 0) {
                for (water_station w : dataList) {
                    List<water> dataList1 = new ArrayList<water>();
                    selectParam = new HashMap<String, String>();
                    selectRequest = new RequestDataBySelect();
                    // 获取查询字段
                    StringBuilder strElement = new StringBuilder();
                    int whereCount = 0;
                    if (startDate != null) {
                        whereCount++;
                        strWhere.append(String.format("latestobservetime >= '%tF %tT'", startDate, startDate));
                    }
                    if (endDate != null) {
                        strWhere.append(String.format(" and latestobservetime <= '%tF %tT'", endDate, endDate));
                    }
                    if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                        strElement = strElement.replace(0, 4, "");
                    }
                    selectRequest.setParam(strWhere.toString());
                    try {
                        selectParam.put("method", "water");
                        selectParam.put("sqlType", "select");
                        selectParam.put("param", JsonUtil.object2Json(selectRequest));
                        message = pc.processRequest(selectParam);
                        dataList1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
                        });
                        if (dataList1 != null && dataList1.size() > 0) {
                            for (water sta : dataList1) {
                                if (w.getStcd().equals(sta.getStationid())) {
                                    w.setStnm(w.getStnm().trim());
                                    w.setLon(w.getLgtd());
                                    w.setLat(w.getLttd());
                                    w.setTime(new DateTime(sta.getLatestobservetime()).toDateTimeString());
                                    w.setStationid(sta.getStationid());
                                    w.setBsnm(sta.getSmallscalewaterstatus().toString());
                                }

                            }
                        }
                    } catch (Exception e) {
                        // TODO: handle exception
                        System.err.println(e.getStackTrace());
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    /**
     * 山洪水情
     *
     * @param addvcd
     * @return
     */
    @Override
    public Object getWaterRainInfoByTimeNArea(Date startDate, Date endDate, String addvcd) {
        List<water_station> dataList = new ArrayList<water_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stcd");
        columns.add("stnm");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setParam(String.format("addvcd ='%s'", addvcd));
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            if (dataList != null && dataList.size() > 0) {
                for (water_station w : dataList) {
                    List<water_rain> dataList1 = new ArrayList<water_rain>();
                    selectParam = new HashMap<String, String>();
                    selectRequest = new RequestDataBySelect();
                    // 获取查询字段
                    columns = new ArrayList<>();
                    columns.add("tm");
                    columns.add("drp");
                    selectRequest.setColumns(columns.toArray(new String[columns.size()]));
                    StringBuilder strWhere = new StringBuilder();
                    int whereCount = 0;
                    if (startDate != null) {
                        whereCount++;
                        strWhere.append(String.format("tm >= '%tF %tT'", startDate, startDate));
                    }
                    if (endDate != null) {
                        strWhere.append(String.format(" and tm <= '%tF %tT'", endDate, endDate));
                    }
                    if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                        strWhere = strWhere.replace(0, 4, "");
                    }
                    selectRequest.setParam(strWhere.toString());
                    try {
                        selectParam.put("method", "water_rain");
                        selectParam.put("sqlType", "select");
                        selectParam.put("param", JsonUtil.object2Json(selectRequest));
                        message = pc.processRequest(selectParam);
                        dataList1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_rain>>() {
                        });

                        if (dataList1 != null && dataList1.size() > 0) {
                            for (water_rain sta : dataList1) {
                                if (w.getStcd().equals(sta.getStcd()))
                                    w.setStnm(w.getStnm().trim());
                                w.setStcd(w.getStcd().trim());
                                w.setTime(new DateTime(sta.getTm()).toDateTimeString());
                                w.setDrp(sta.getDrp());
                            }
                        }
                    } catch (Exception e) {
                        // TODO: handle exception
                        System.err.println(e.getStackTrace());
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    @Override
    public Object getWaterRainInfoByTimeNStationIds(Date startDate, Date endDate, String[] stations) {
        List<water_station> dataList = new ArrayList<water_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stcd");
        columns.add("stnm");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        if (stations != null && stations.length > 0) {
            strWhere.append(" stcd in (");
            String tempString = "";
            for (String stationid : stations) {
                tempString += String.format("'%s',", stationid);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            if (dataList != null && dataList.size() > 0) {
                for (water_station w : dataList) {
                    List<water_rain> dataList1 = new ArrayList<water_rain>();
                    selectParam = new HashMap<String, String>();
                    selectRequest = new RequestDataBySelect();
                    // 获取查询字段
                    columns = new ArrayList<>();
                    columns.add("tm");
                    columns.add("drp");
                    selectRequest.setColumns(columns.toArray(new String[columns.size()]));
                    strWhere = new StringBuilder();
                    int whereCount = 0;
                    if (startDate != null) {
                        whereCount++;
                        strWhere.append(String.format("tm >= '%tF %tT'", startDate, startDate));
                    }
                    if (endDate != null) {
                        strWhere.append(String.format(" and tm <= '%tF %tT'", endDate, endDate));
                    }
                    if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                        strWhere = strWhere.replace(0, 4, "");
                    }
                    selectRequest.setParam(strWhere.toString());
                    try {
                        selectParam.put("method", "water_rain");
                        selectParam.put("sqlType", "select");
                        selectParam.put("param", JsonUtil.object2Json(selectRequest));
                        message = pc.processRequest(selectParam);
                        dataList1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_rain>>() {
                        });
                        if (dataList1 != null && dataList1.size() > 0) {
                            for (water_rain sta : dataList1) {
                                if (w.getStcd().equals(sta.getStcd()))
                                    w.setStnm(w.getStnm().trim());
                                w.setStcd(w.getStcd().trim());
                                w.setTime(new DateTime(sta.getTm()).toDateTimeString());
                                w.setDrp(sta.getDrp());
                            }
                        }
                    } catch (Exception e) {
                        // TODO: handle exception
                        System.err.println(e.getStackTrace());
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    /**
     * 土壤湿度
     *
     * @param stationid
     * @return
     */
    @Override
    public Object getSoilHumidityByTimeNStationids(Date startDate, Date endDate, String stationid) {
        List<soilHumidity> dataList = new ArrayList<soilHumidity>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("to_char(observetime, 'yyyy-MM-dd HH24:MI:SS') as observetime");
        columns.add("level");
        columns.add("relhumidity");
        columns.add("weightwaterypercent");
        columns.add("effectivewateryvalue");
        columns.add("lotmark");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observetime >='%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observetime <='%tF %tT'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(stationid)) {
            strWhere.append(String.format(" and stationid = '%s'", stationid));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "soil_humidity");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<soilHumidity>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    /**
     * 日历史数据
     *
     * @param stationid 站号
     * @param element   要素
     * @return
     */
    @Override
    public Object getHistoryDayDataByTimeNStationIds(String start, String end, String stationid, String element) {
        List<sum_sun_day_data> dataList = new ArrayList<sum_sun_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("year");
        columns.add("month");
        columns.add("sumvalue");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        String[] split1 = start.split("-");
        String startDate = split1[0];
        String[] split2 = end.split("-");
        String endDate = split2[0];
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("year >='%s'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and year <='%s'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(stationid)) {
            strWhere.append(String.format(" and stationid = '%s'", stationid));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            //根据参数查询不同的表
            StringBuilder strMethod = new StringBuilder();
            if (!StringUtil.IsNullOrEmpty(element)) {
                strMethod.append("sum_");
                strMethod.append(element);
                strMethod.append("_day_data");
                selectParam.put("method", strMethod.toString());
            } else {
                selectParam.put("method", "sum_sun_day_data");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_sun_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    /**
     * 月历史数据
     *
     * @param stationid
     * @param element
     * @return
     */
    @Override
    public Object getHistoryMonthDataByTimeNStationIds(String start, String end, String stationid, String element) {
        List<sum_sun_day_data> dataList = new ArrayList<sum_sun_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("year");
        columns.add("month");
        columns.add("sumvalue");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        String[] split1 = start.split("-");
        String startDate = split1[0];
        String[] split2 = end.split("-");
        String endDate = split2[0];
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("year >='%s'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and year <='%s'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(stationid)) {
            strWhere.append(String.format(" and stationid = '%s'", stationid));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            //根据参数查询不同的表
            StringBuilder strMethod = new StringBuilder();
            if (!StringUtil.IsNullOrEmpty(element)) {
                strMethod.append("sum_");
                strMethod.append(element);
                strMethod.append("_month_data");
                selectParam.put("method", strMethod.toString());
            } else {
                selectParam.put("method", "sum_sun_month_data");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_sun_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    /**
     * 年历史数据
     *
     * @param stationid
     * @param element
     * @return
     */
    @Override
    public Object getHistoryYearDataByTimeNStationIds(String start, String end, String stationid, String element) {
        List<sum_sun_day_data> dataList = new ArrayList<sum_sun_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("year");
        columns.add("sumvalue");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        String[] split1 = start.split("-");
        String startDate = split1[0];
        String[] split2 = end.split("-");
        String endDate = split2[0];
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("year >='%s'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and year <='%s'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(stationid)) {
            strWhere.append(String.format(" and stationid = '%s'", stationid));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            //根据参数查询不同的表
            StringBuilder strMethod = new StringBuilder();
            if (!StringUtil.IsNullOrEmpty(element)) {
                strMethod.append("sum_");
                strMethod.append(element);
                strMethod.append("_year_data");
                selectParam.put("method", strMethod.toString());
            } else {
                selectParam.put("method", "sum_sun_year_data");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_sun_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    @Override
    public List<township_forecast> getTownForecastByTimeNArea(township_forecast townshipForecast) {
        List<township_forecast> forecastInfoList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("weather1");
        columns.add("winds");
        columns.add("windd");
        columns.add("city");
        columns.add("areaname");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (townshipForecast.getDatechar() != null) {
            whereCount++;
            strWhere.append(String.format("datechar = '%tF %tT'", townshipForecast.getDatechar(), townshipForecast.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(townshipForecast.getTimechar())) {
            strWhere.append(String.format(" and timechar = '%s'", townshipForecast.getTimechar()));
        }
        if (!StringUtil.IsNullOrEmpty(townshipForecast.getCity())) {
            strWhere.append(String.format(" and city = '%s'", townshipForecast.getCity()));
        }
        if (!StringUtil.IsNullOrEmpty(townshipForecast.getStationid())) {
            strWhere.append(String.format(" and areaname = '%s'", townshipForecast.getAreaname()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "township_forecast_provincetemp");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            forecastInfoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return forecastInfoList;
    }

    @Override
    public List<township_forecast> getTownForecastByTimeNStationids(township_forecast townshipForecast) {
        List<township_forecast> forecastInfoList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("weather1");
        columns.add("winds");
        columns.add("windd");
        columns.add("city");
        columns.add("areaname");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (townshipForecast.getDatechar() != null) {
            whereCount++;
            strWhere.append(String.format("datechar = '%tF %tT'", townshipForecast.getDatechar(), townshipForecast.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(townshipForecast.getTimechar())) {
            strWhere.append(String.format(" and timechar = '%s'", townshipForecast.getTimechar()));
        }
        if (!StringUtil.IsNullOrEmpty(townshipForecast.getStationid())) {
            strWhere.append(String.format(" and stationid = '%s'", townshipForecast.getStationid()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "township_forecast_provincetemp");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            forecastInfoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return forecastInfoList;
    }

    /**
     * 预警信号
     *
     * @param area
     * @param city
     * @return
     */
    @Override
    public Object getWarnSignalByTimeNArea(Date startDate, Date endDate, String area, String city) {
        List<warn_signal_info> dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("area");
        columns.add("type");
        columns.add("color");
        columns.add("city");
        columns.add("standard");
        columns.add("defenseguide");
        columns.add("to_char(announcedtime, 'yyyy-MM-dd HH24:MI:SS') as announcedtime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("announcedtime >= '%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and announcedtime <= '%tF %tT'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(area)) {
            strWhere.append(String.format(" and area = '%s'", area));
        }
        if (!StringUtil.IsNullOrEmpty(area)) {
            strWhere.append(String.format(" and city = '%s'", city));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "warn_signal_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warn_signal_info>>() {
            });
            for (warn_signal_info warn : dataList) {
                warn.setTime(new DateTime(warn.getAnnouncedtime()).toDateTimeString());
            }
        } catch (Exception e) {
            // TODO: handle exception
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    /**
     * 组网雷达
     *
     * @param datechar
     * @param
     * @param ldtype
     * @return
     */
    @Override
    public Object getUnionRadarByTimeNType(Date datechar, String timechar, String ldtype) {
        List<zwdoppler> dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (datechar != null) {
            whereCount++;
            strWhere.append(String.format("datechar = '%tF %tT'", datechar, datechar));
        }
        if (!StringUtil.IsNullOrEmpty(timechar)) {
            strWhere.append(String.format(" and timechar = '%s'", timechar));
        }
        if (!StringUtil.IsNullOrEmpty(ldtype)) {
            strWhere.append(String.format(" and ldtype = '%s'", ldtype));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "zwdoppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<zwdoppler>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    /**
     * 云图文件
     *
     * @param datechar
     * @param timechar
     * @param yttype
     * @return
     */
    @Override
    public List<satellitenephoram> getFYInfo(Date datechar, String timechar, String yttype) {
        List<satellitenephoram> dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (datechar != null) {
            whereCount++;
            strWhere.append(String.format("datechar = '%tF %tT'", datechar, datechar));
        }
        if (!StringUtil.IsNullOrEmpty(timechar)) {
            strWhere.append(String.format(" and timechar = '%s'", timechar));
        }
        if (!StringUtil.IsNullOrEmpty(yttype)) {
            strWhere.append(String.format(" and yttype = '%s'", yttype));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "satellitenephoram");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<satellitenephoram>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception

        }
        return dataList;
    }

    /**
     * 指数气象
     *
     * @param zhiShu
     * @return
     */
    @Override
    public Object getZhishu(zhiShu zhiShu) {
        List<zhiShu> dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Date datechar = zhiShu.getDatechar();
        String timechar = zhiShu.getTimechar();
        String cityid = zhiShu.getCityid();
        String cityname = zhiShu.getCityname();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (datechar != null) {
            whereCount++;
            strWhere.append(String.format("datechar = '%tF %tT'", datechar, datechar));
        }
        if (!StringUtil.IsNullOrEmpty(timechar)) {
            strWhere.append(String.format(" and timechar = '%s'", timechar));
        }
        if (!StringUtil.IsNullOrEmpty(cityid)) {
            strWhere.append(String.format(" and cityid = '%s'", cityid));
        }
        if (!StringUtil.IsNullOrEmpty(cityid)) {
            strWhere.append(String.format(" and cityname = '%s'", cityname));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "zhishu");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<zhiShu>>() {
            });
            for (zhiShu zs : dataList) {
                zs.setLatitude(null);
                zs.setLongitude(null);
            }
        } catch (Exception e) {
            // TODO: handle exception
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }


    /**
     * 获取雷达图
     *
     * @param request
     * @return
     * @throws ParseException
     */
    @Override
    public List<doppler> getDopplerImage1(HttpServletRequest request) throws ParseException {
        List<doppler> dopplerList = new ArrayList<>();
        String date = request.getParameter("datechar");
        Date datechar = null;
        if (!StringUtil.IsNullOrEmpty(date)) {
            datechar = DateTime.parseDateTime(date).toDate();
        }
        String timechar = request.getParameter("timechar");
        String stationid = request.getParameter("stationid");
        String ldtype = request.getParameter("ldtype");
        String eleva = request.getParameter("elevation");
        //投影类型
        String type = request.getParameter("type");
        Float elevation = null;
        if (!StringUtil.IsNullOrEmpty(eleva)) {
            elevation = Float.parseFloat(eleva);
        }
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        //返回字段
        String[] columns = new String[]{"to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar", "timechar", "stationid", "ldtype", "elevation",
                "path", "west", "south", "east", "north", "fwest", "fsouth", "feast", "fnorth"};
        selectRequest.setColumns(columns);
        int whereCount = 0;
        if (datechar != null) {
            whereCount++;
            strWhere.append(String.format("datechar = '%tF %tT'", datechar, datechar));
        }
        if (!StringUtil.IsNullOrEmpty(timechar)) {
            strWhere.append(String.format(" and timechar = '%s'", timechar));
        }
        if (!StringUtil.IsNullOrEmpty(stationid)) {
            strWhere.append(String.format(" and stationid = '%s'", stationid));
        }
        if (!StringUtil.IsNullOrEmpty(ldtype)) {
            strWhere.append(String.format(" and ldtype = '%s'", ldtype));
        }
        if (elevation != null) {
            strWhere.append(String.format(" and elevation = '%f'", elevation));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "doppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dopplerList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            });
            for (doppler doppler : dopplerList) {
                String fileName = "ld_png_file" + "_" + new DateTime(doppler.getDatechar()).toDateTimeString("yyyy-MM-dd") + "_" + doppler.getTimechar().trim();
                String serviceFilePath = "";
                // 下载
                fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                String path = request.getContextPath();
                String basePath = DbConfig.IP + path
                        + "/Temp/File/";
                String serviceUrl = basePath + fileName;
                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                serviceFilePath = urlpath + fileName;// 服务器文件
                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                String dopplerPath = doppler.getPath();
                // \\ld_file\\20200829.160143.01.26.736
                String[] split = dopplerPath.split("\\\\");
                String file = split[2];
                String[] sp = file.split("\\.");
                String time = sp[0];
                String dChar = time.substring(0, 4) + "-" + time.substring(4, 6) + "-" + time.substring(6, 8);
                // 如果目录中不存在文件，下载雷达文件到temp目录
                File serviceFile = new File(serviceFilePath);// 服务器文件
                if (!serviceFile.exists()) {// 把文件上传到服务器{
                    Map<String, Object> queryMap = new HashMap<String, Object>();
                    queryMap.put("datechar", dChar);
                    if (!StringUtil.IsNullOrEmpty(type) && "M".equals(type)) {
                        queryMap.put("type", "ld_png_file_m");
                    } else if (!StringUtil.IsNullOrEmpty(type) && "L".equals(type)) {
                        queryMap.put("type", "ld_png_file");
                    }
                    queryMap.put("collectionName", "ld_png_file");
                    byte[] data = ms.selectData(queryMap);
                    if (data == null) {
                        serviceFilePath = "";
                    } else {
                        FileUtil.bytesToFile(data, serviceFilePath);
                    }
                }
                if (!serviceFilePath.equals("")) {
                    serviceFilePath = serviceUrl;
                }
                String filePath = serviceFilePath;
                doppler.setPath(filePath);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dopplerList;
    }

    @Override
    public List<satellitenephoram> getFYImages1(HttpServletRequest request) throws ParseException {
        List<satellitenephoram> dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        String date = request.getParameter("datechar");
        Date datechar = null;
        if (!StringUtil.IsNullOrEmpty(date)) {
            datechar = DateTime.parseDateTime(date).toDate();
        }
        String timechar = request.getParameter("timechar");
        String yttype = request.getParameter("yttype");
        String type = request.getParameter("type");
        int whereCount = 0;
        if (datechar != null) {
            whereCount++;
            strWhere.append(String.format("datechar = '%tF %tT'", datechar, datechar));
        }
        if (!StringUtil.IsNullOrEmpty(timechar)) {
            strWhere.append(String.format(" and timechar = '%s'", timechar));
        }
        if (!StringUtil.IsNullOrEmpty(yttype)) {
            strWhere.append(String.format(" and yttype = '%s'", yttype));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "satellitenephoram");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<satellitenephoram>>() {
            });
            for (satellitenephoram state : dataList) {
                String fileName = "yt_png_file" + "_" + new DateTime(state.getDatechar()).toDateTimeString("yyyy-MM-dd") + "_" + state.getTimechar().trim() + "_FY2E.AWX";
                String serviceFilePath = "";
                // 下载
                fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                String path = request.getContextPath();
                String basePath = DbConfig.IP + path
                        + "/Temp/File/";
                String serviceUrl = basePath + fileName;
                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                serviceFilePath = urlpath + fileName;// 服务器文件
                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                String statePath = state.getPath();
                // \yt_file\ANI_IR1_R01_20200623_1500_FY2E.AWX
                String[] split = statePath.split("\\\\");
                String file = split[2];
                // 如果目录中不存在文件，下载雷达文件到temp目录
                File serviceFile = new File(serviceFilePath);// 服务器文件
                if (!serviceFile.exists()) {// 把文件上传到服务器{
                    String[] fileSplit = file.split("_");
                    String ttype = fileSplit[1];
                    if (ttype.equals("IR1")) {
                        yttype = "FY2E红外图像";
                    } else if (ttype.equals("IR2")) {
                        yttype = "FY2E分裂窗图像";
                    } else if (ttype.equals("IR3")) {
                        yttype = "FY2E水汽图像";
                    } else if (ttype.equals("IR4")) {
                        yttype = "FY2E水汽图像";
                    } else if (ttype.equals("VIS")) {
                        yttype = "FY2E可见光图像";
                    }
                    String dateTime = fileSplit[3];
                    String dchar = dateTime.substring(0, 4) + "-" + dateTime.substring(4, 6) + "-" + dateTime.substring(6, 8);
                    String tchar = fileSplit[4];
                    //查询数据库
                    Map<String, Object> queryMap = new HashMap<String, Object>();
                    queryMap.put("datechar", dchar);
                    queryMap.put("timechar", tchar);
                    if (!StringUtil.IsNullOrEmpty(type) && "M".equals(type)) {
                        queryMap.put("type", "yt_png_file_m");
                    } else if (!StringUtil.IsNullOrEmpty(type) && "L".equals(type)) {
                        queryMap.put("type", "yt_png_file");
                    }
                    queryMap.put("collectionName", "yt_png_file");
                    byte[] data = ms.selectData(queryMap);
                    if (data == null) {
                        serviceFilePath = "";
                    } else {
                        FileUtil.bytesToFile(data, serviceFilePath);
                    }
                }
                if (!serviceFilePath.equals("")) {
                    serviceFilePath = serviceUrl;
                }
                String filePath = serviceFilePath;
                state.setPath(filePath);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public Object getSmallScaleByDistince(Date newTime, String lon, String lat) {
        //MediumSmallScale
        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        dataBySelect.setColumns(new String[]{"(" + lon + "-longitude)*(" + lon + "-longitude)+(" + lat + "-latitude)*(" + lat + "-latitude) as dis",
                "stationName", "dryBulbTemp", "maxTemp", "minTemp", "rain", "windVelocity", "relHumidity"});
        dataBySelect.setSort(new String[]{"dis asc"});
        dataBySelect.setLimit(1);
        Map<String, String> map = new HashMap<String, String>();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(newTime);

        List<msgmediumsmallscale> infos = new ArrayList<msgmediumsmallscale>();
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "(SELECT stationname,longitude,latitude,drybulbtemp,maxtemp,mintemp,rain,windvelocity,relhumidity FROM msgmediumsmallscale  where observtime='" + dateString + "' and city like'" + DbConfig.CITY + "%' and drybulbtemp<>-65535 and windvelocity<>-65535 and relhumidity <>-65535 ) a");
            map.put("sqlType", "select");
            String result = pc.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<msgmediumsmallscale>>() {
                });
                if (infos.size() > 0)
                    infos.get(0).setObservtime(newTime);
                return new ResultObj("查询成功", infos, true);
            }
        } catch (Exception e) {
            return new ResultObj("查询失败", e.getMessage(), false);
        }
    }

    @Override
    public Date getScaleNewDate() {
        // TODO 获取最新实况数据
        Date date = new Date();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"year||'-'||month||'-'||day||' '||hour||':00:00' as observtime"};//to_char(observtime, 'yyyy-MM-dd HH24:MI:SS')
        selectRequest.setColumns(columns);
        selectRequest.setParam("type='SmallScale'");
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "collect_time");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            date = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            }).get(0).getObservtime();
        } catch (Exception e) {
            // TODO: handle exception
        }
        return date;
    }

    @Override
    public String getJXHTimeChar(String date) {
        List<GridData> resultList = new ArrayList<GridData>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"max(timechar) as timechar"});
        selectRequest.setParam("datechar='" + date + "'");
        try {
            selectParam.put("method", "grid_data");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<GridData>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (resultList.size() > 0) {
            String timechar = resultList.get(0).getTimechar();
            if (StringUtil.IsNullOrEmpty(timechar))
                timechar = "08";
            return timechar;
        } else
            return "08";
    }

    @Override
    public List<msgmediumsmallscale> tempQuery() {
        Date nowdate = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String startDate = simpleDateFormat.format(nowdate);
        String endDate = simpleDateFormat.format(nowdate);
        List<msgmediumsmallscale> dataList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format(" observtime>='%s'", startDate + " 00:00:00"));
        strWhere.append(String.format(" and observtime <='%s'", endDate + " 23:00:00"));
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        selectRequest.setSort(new String[]{" observtime desc"});
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    /***
     * 初始化常规产品类型
     * @return
     */
    @Override
    public List<job_model> InitProType() {
        List<job_model> result = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("onetype");
        columns.add("twotype");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"onetype desc"});
        try {
            selectParam.put("method", "job_model");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<job_model>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return result;
    }

    @Override
    public List<?> queryZhcxZhdXq(String wybh) {
        List dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam(String.format("pp_id='%s'", wybh));
        try {
            selectParam.put("method", "potential_points");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    @Override
    public Object getHistoryByElement(String element, String date,String county,String advname,String result) {
        List<sum_sun_day_data> dataList = new ArrayList<sum_sun_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element1 ="";
        switch (element){
            case "bestWind":
                element1="wind";
                break;
            case "maxWind":
                element1="wind";
                break;
            default:
                element1=element;
        }
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取年、月、日
        int year1 = 1970;
        int year2 = currentDate.getYear();
        int month = currentDate.getMonthValue();
        int day = currentDate.getDayOfMonth();
        int xun = 0;
        if (day >= 1 && day <= 10){
            xun = 1;
        }else if (day >= 11 && day <= 20){
            xun = 2;
        }else if (day >= 21 && day <= 31){
            xun = 3;
        }
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("*");
        switch (date){
            case "day":
                columns.add("CONCAT(year, '-', LPAD(TO_CHAR(month, 'FM00'), 2, '0'), '-', LPAD(TO_CHAR(day, 'FM00'), 2, '0')) AS times");
                break;
            case "td":
                columns.add("CONCAT(year, '-', LPAD(TO_CHAR(month, 'FM00'), 2, '0'), '-', LPAD(TO_CHAR(td, 'FM00'), 2, '0')) AS times");
                break;
            case "month":
                columns.add("CONCAT(year, '-', LPAD(TO_CHAR(month, 'FM00'), 2, '0')) AS times");
                break;
            case "year":
                columns.add("CONCAT(year, '-', LPAD(TO_CHAR(month, 'FM00'), 2, '0'), '-', LPAD(TO_CHAR(day, 'FM00'), 2, '0')) AS times");
                break;

        }
         if (date.equals("day")){//查询日
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (element.equals("bestWind")){
            strWhere.append(" and stationid IN (").append(result).append(")");
            strWhere.append(" and year BETWEEN ").append(year1).append(" AND ").append(year2);
            strWhere.append(" and month = ").append(month);
            strWhere.append(" and day = ").append(day);
            strWhere.append(" and sumindicatorname = '极大风速' ");
            strWhere.append(String.format(" ORDER BY sumvalue DESC"));
        }else if (element.equals("maxWind")){
            strWhere.append(" and stationid IN (").append(result).append(")");
            strWhere.append(" and year BETWEEN ").append(year1).append(" AND ").append(year2);
            strWhere.append(" and month = ").append(month);
            strWhere.append(" and day = ").append(day);
            strWhere.append(" and sumindicatorname = '最大风速' ");
            strWhere.append(String.format(" ORDER BY sumvalue DESC"));
        } else if (element.equals("temp")) {
            strWhere.append(" and stationid IN (").append(result).append(")");
            strWhere.append(" and year BETWEEN ").append(year1).append(" AND ").append(year2);
            strWhere.append(" and month = ").append(month);
            strWhere.append(" and day = ").append(day);
            strWhere.append(" and sumindicatorname = '最高气温' ");
            strWhere.append(String.format(" ORDER BY sumvalue DESC"));
        } else {
            strWhere.append(" and stationid IN (").append(result).append(")");
            strWhere.append(" and year BETWEEN ").append(year1).append(" AND ").append(year2);
            strWhere.append(" and month = ").append(month);
            strWhere.append(" and day = ").append(day);
            strWhere.append(String.format(" ORDER BY sumvalue DESC"));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());
         }else if(date.equals("td")){//查询旬
             selectRequest.setColumns(columns.toArray(new String[columns.size()]));
             StringBuilder strWhere = new StringBuilder();
             int whereCount = 0;
             strWhere.append(" and stationid IN (").append(result).append(")");
             strWhere.append(" and year BETWEEN ").append(year1).append(" AND ").append(year2);
             strWhere.append(" and month = ").append(month);
             strWhere.append(" and td = ").append(xun);
             strWhere.append(String.format(" ORDER BY sumvalue DESC"));
             if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                 strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
             }
             selectRequest.setParam(strWhere.toString());
        }else if(date.equals("month")){//查询月
             selectRequest.setColumns(columns.toArray(new String[columns.size()]));
             StringBuilder strWhere = new StringBuilder();
             int whereCount = 0;
             strWhere.append(" and stationid IN (").append(result).append(")");
             strWhere.append(" and year BETWEEN ").append(year1).append(" AND ").append(year2);
             strWhere.append(" and month = ").append(month);
             strWhere.append(String.format(" ORDER BY sumvalue DESC"));
             if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                 strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
             }
             selectRequest.setParam(strWhere.toString());
         }else if(date.equals("year")){//查询旬
             selectRequest.setColumns(columns.toArray(new String[columns.size()]));
             StringBuilder strWhere = new StringBuilder();
             int whereCount = 0;
             strWhere.append(" and stationid IN (").append(result).append(")");
             strWhere.append(" and year BETWEEN ").append(year1).append(" AND ").append(year2);
             strWhere.append(" and month BETWEEN  ").append(1).append(" AND ").append(month);
             strWhere.append(" and day BETWEEN ").append(1).append(" AND ").append(day);
             strWhere.append(String.format(" ORDER BY sumvalue DESC"));
             if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                 strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
             }
             selectRequest.setParam(strWhere.toString());
         }
        try {
            //根据参数查询不同的表
            StringBuilder strMethod = new StringBuilder();
            if (date.equals("year")){
                date = "day";
            }
            if (!StringUtil.IsNullOrEmpty(element)) {
                strMethod.append("sum_");
                strMethod.append(element1);
                strMethod.append("_");
                strMethod.append(date);
                strMethod.append("_data");
                selectParam.put("method", strMethod.toString());
            } else {
                strMethod.append("sum_sun_");
                strMethod.append(date);
                strMethod.append("_data");
                selectParam.put("method", strMethod.toString());
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_sun_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    @Override
    public List<sum_rain_day_data> getQiHouByTemp(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        calendar.set(Calendar.DAY_OF_MONTH, 1);  // 设置为当前月的第一天
        calendar.set(Calendar.HOUR_OF_DAY, 0);   // 设置小时为 00
        calendar.set(Calendar.MINUTE, 0);        // 设置分钟为 00
        calendar.set(Calendar.SECOND, 0);        // 设置秒为 00
        calendar.set(Calendar.MILLISECOND, 0);   // 设置毫秒为 00
        Date startTime = calendar.getTime();
        // 设置 endTime 为当前时间的最后一刻
        calendar.setTime(new Date());  // 获取当前时间
        calendar.set(Calendar.MILLISECOND, 999); // 设置毫秒为 999
        Date endTime = calendar.getTime();
        // 转换为 Timestamp 类型，用于 SQL 查询
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedStartTimestamp = sdf.format(startTime.getTime());
        String formattedEndTimestamp = sdf.format(endTime.getTime());
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("MIN(mintemp) AS sumvalue");
        columns.add("TO_CHAR(observtime, 'MM月DD日HH时') AS staticdate ");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and observtime BETWEEN '").append(formattedStartTimestamp).append("' AND '").append(formattedEndTimestamp).append("'");
        strWhere.append(" and mintemp <> '-65535'");
        strWhere.append(" GROUP BY observtime");
        strWhere.append(" ORDER BY sumvalue ASC LIMIT 1");    // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public List<sum_rain_day_data> getQiHouByTemp1(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("sumvalue");
        columns.add("staticdate");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and sumindicatorname like '%最低气温%'");  // 添加你需要的筛选条件
        strWhere.append(" and year = '" + year + "'");
        strWhere.append(" and month = '" + month + "'");
        strWhere.append(" and day between '1' and '" + day + "'");
        strWhere.append(" ORDER BY sumvalue ASC");
        strWhere.append(" LIMIT 1");  // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "sum_temp_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public List<sum_rain_day_data> getQiHouByTemp2(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        calendar.set(Calendar.DAY_OF_MONTH, 1);  // 设置为当前月的第一天
        calendar.set(Calendar.HOUR_OF_DAY, 0);   // 设置小时为 00
        calendar.set(Calendar.MINUTE, 0);        // 设置分钟为 00
        calendar.set(Calendar.SECOND, 0);        // 设置秒为 00
        calendar.set(Calendar.MILLISECOND, 0);   // 设置毫秒为 00
        Date startTime = calendar.getTime();
        // 设置 endTime 为当前时间的最后一刻
        calendar.setTime(new Date());  // 获取当前时间
        calendar.set(Calendar.MILLISECOND, 999); // 设置毫秒为 999
        Date endTime = calendar.getTime();
        // 转换为 Timestamp 类型，用于 SQL 查询
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedStartTimestamp = sdf.format(startTime.getTime());
        String formattedEndTimestamp = sdf.format(endTime.getTime());
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("ROUND(AVG(drybulbtemp)::numeric, 1) AS sumvalue");
        columns.add("TO_CHAR(observtime,'YYYY年MM月DD日' )AS staticdate");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and observtime between '"+formattedStartTimestamp+"' and '"+formattedEndTimestamp+"'");
        strWhere.append(" and drybulbtemp <> '-65535'");
        strWhere.append(" GROUP BY observtime");
        strWhere.append(" ORDER BY observtime DESC LIMIT 1");    // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public List<sum_rain_day_data> getQiHouByRain(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        calendar.set(Calendar.DAY_OF_MONTH, 1);  // 设置为当前月的第一天
        calendar.set(Calendar.HOUR_OF_DAY, 0);   // 设置小时为 00
        calendar.set(Calendar.MINUTE, 0);        // 设置分钟为 00
        calendar.set(Calendar.SECOND, 0);        // 设置秒为 00
        calendar.set(Calendar.MILLISECOND, 0);   // 设置毫秒为 00
        Date startTime = calendar.getTime();
        // 设置 endTime 为当前时间的最后一刻
        calendar.setTime(new Date());  // 获取当前时间
        calendar.set(Calendar.MILLISECOND, 999); // 设置毫秒为 999
        Date endTime = calendar.getTime();
        // 转换为 Timestamp 类型，用于 SQL 查询
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedStartTimestamp = sdf.format(startTime.getTime());
        String formattedEndTimestamp = sdf.format(endTime.getTime());
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("MAX(maxtemp) AS sumvalue");
        columns.add("TO_CHAR(observtime, 'MM月DD日HH时') AS staticdate ");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and observtime between '"+formattedStartTimestamp+"' and '"+formattedEndTimestamp+"'");
        strWhere.append(" and maxtemp <> '-65535'");
        strWhere.append(" GROUP BY observtime");
        strWhere.append(" ORDER BY sumvalue DESC LIMIT 1");
        //strWhere.append(" LIMIT 1");  // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public List<sum_rain_day_data> getQiHouByRain11(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        calendar.set(Calendar.DAY_OF_MONTH, 1);  // 设置为当前月的第一天
        calendar.set(Calendar.HOUR_OF_DAY, 0);   // 设置小时为 00
        calendar.set(Calendar.MINUTE, 0);        // 设置分钟为 00
        calendar.set(Calendar.SECOND, 0);        // 设置秒为 00
        calendar.set(Calendar.MILLISECOND, 0);   // 设置毫秒为 00
        Date startTime = calendar.getTime();
        // 设置 endTime 为当前时间的最后一刻
        calendar.setTime(new Date());  // 获取当前时间
        calendar.set(Calendar.MILLISECOND, 999); // 设置毫秒为 999
        Date endTime = calendar.getTime();
        // 转换为 Timestamp 类型，用于 SQL 查询
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedStartTimestamp = sdf.format(startTime.getTime());
        String formattedEndTimestamp = sdf.format(endTime.getTime());
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("ROUND(SUM(rain)::numeric,1) AS sumvalue");
        columns.add("TO_CHAR(observtime, 'YYYY年MM月DD日') AS staticdate ");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and observtime between '"+formattedStartTimestamp+"' and '"+formattedEndTimestamp+"'");
        strWhere.append(" and rain <> '-65535'");
        strWhere.append(" GROUP BY observtime");
        strWhere.append(" ORDER BY sumvalue DESC LIMIT 1");
        //strWhere.append(" LIMIT 1");  // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public List<sum_rain_day_data> getQiHouByRain1(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("MAX(sumvalue) AS sumvalue");
        columns.add(" CONCAT(LPAD(month::text, 2, '0'), '月', LPAD(day::text, 2, '0'), '日') AS staticdate ");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and sumindicatorname like '%总雨量%'");  // 添加你需要的筛选条件
        strWhere.append(" and year = '" + year + "'");
        strWhere.append(" and month = '" + month + "'");
        strWhere.append(" and day between '1' and '" + day + "'");
        strWhere.append(" GROUP BY  LPAD(month::text, 2, '0'), LPAD(day::text, 2, '0')");
        strWhere.append(" ORDER BY staticdate");   // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "sum_rain_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public List<sum_rain_day_data> getQiHouByRain2(String result) {
        Date date = new Date();
        // 获取当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH)+1;
        // 设置 startTime 为当前月的第一天 00:00:00
        calendar.set(Calendar.DAY_OF_MONTH, 1);  // 设置为当前月的第一天
        calendar.set(Calendar.HOUR_OF_DAY, 0);   // 设置小时为 00
        calendar.set(Calendar.MINUTE, 0);        // 设置分钟为 00
        calendar.set(Calendar.SECOND, 0);        // 设置秒为 00
        calendar.set(Calendar.MILLISECOND, 0);   // 设置毫秒为 00
        Date startTime = calendar.getTime();
        // 设置 endTime 为当前时间的最后一刻
        calendar.setTime(new Date());  // 获取当前时间
        calendar.set(Calendar.MILLISECOND, 999); // 设置毫秒为 999
        Date endTime = calendar.getTime();
        // 转换为 Timestamp 类型，用于 SQL 查询
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedStartTimestamp = sdf.format(startTime.getTime());
        String formattedEndTimestamp = sdf.format(endTime.getTime());
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("MAX(rain) AS sumvalue");
        columns.add("TO_CHAR(observtime, 'MM月DD日HH时') AS staticdate  ");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and observtime BETWEEN '" + formattedStartTimestamp + "' AND '" + formattedEndTimestamp + "'");
        strWhere.append(" GROUP BY observtime");
        strWhere.append(" ORDER BY sumvalue DESC");
        strWhere.append(" LIMIT 1");
        // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public List<sum_rain_day_data> getQiHouByTemp11(String result) {
        Date date = new Date();
// 获取当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份

// 设置 startTime 为当前年 1 月 1 日 00:00:00
        calendar.set(Calendar.YEAR, year);    // 设置年份为当前年份
        calendar.set(Calendar.MONTH, Calendar.JANUARY);  // 设置为 1 月（0 索引，0 = 1 月）
        calendar.set(Calendar.DAY_OF_MONTH, 1);  // 设置为 1 日
        calendar.set(Calendar.HOUR_OF_DAY, 0);   // 设置小时为 00
        calendar.set(Calendar.MINUTE, 0);        // 设置分钟为 00
        calendar.set(Calendar.SECOND, 0);        // 设置秒为 00
        calendar.set(Calendar.MILLISECOND, 0);   // 设置毫秒为 00
        Date startTime = calendar.getTime();  // 获取设置后的时间
// 转换为 Timestamp 类型，用于 SQL 查询
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // 设置 endTime 为当前时间的最后一刻
        calendar.setTime(new Date());  // 获取当前时间
        calendar.set(Calendar.MILLISECOND, 999); // 设置毫秒为 999
        Date endTime = calendar.getTime();
        String formattedStartTimestamp = sdf.format(startTime.getTime());
        String formattedEndTimestamp = sdf.format(endTime.getTime());
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("MAX(rain) AS sumvalue");
        columns.add("TO_CHAR(observtime, 'MM月DD日HH时') AS staticdate  ");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and observtime BETWEEN '" + formattedStartTimestamp + "' AND '" + formattedEndTimestamp + "'");
        strWhere.append(" GROUP BY observtime");
        strWhere.append(" ORDER BY sumvalue DESC");
        strWhere.append(" LIMIT 1");
        // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }



    @Override
    public List<sum_rain_day_data> getQiHouByTemp6(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("ROUND(AVG(sumvalue), 1) AS sumvalue");
        columns.add("staticdate");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and sumindicatorname like '%平均气温%'");
        strWhere.append(" and year = '" + year + "'");
        strWhere.append(" and month between '1' and '" + month + "'");
        strWhere.append(" and day between '1' and '" + day + "'");

        strWhere.append(" GROUP BY staticdate");
        strWhere.append(" ORDER BY staticdate");  // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "sum_temp_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    @Override
    public List<sum_rain_day_data> getQiHouByTemp8(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("MIN(sumvalue) AS sumvalue");
        columns.add("month || '月' || day || '日' AS staticdate");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and sumindicatorname like '%最低气温%'");  // 添加你需要的筛选条件
        strWhere.append(" and year = '" + year + "'");
        strWhere.append(" and month between '1' and '" + month + "'");
        strWhere.append(" and day between '1' and '" + day + "'");
        strWhere.append(" GROUP BY MONTH, DAY");
        strWhere.append(" ORDER BY staticdate");   // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "sum_temp_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public List<sum_rain_day_data> getQiHouByTemp7(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("MAX(sumvalue) AS sumvalue");
        columns.add("month || '月' || day || '日' AS staticdate");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and sumindicatorname like '%最高气温%'");  // 添加你需要的筛选条件
        strWhere.append(" and year = '" + year + "'");
        strWhere.append(" and month between '1' and '" + month + "'");
        strWhere.append(" and day between '1' and '" + day + "'");
        strWhere.append(" GROUP BY MONTH, DAY");
        strWhere.append(" ORDER BY staticdate");
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "sum_temp_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public List<sum_rain_day_data> getQiHouByTemp9(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("ROUND(SUM(sumvalue)::numeric,1) AS sumvalue");
        columns.add("staticdate");

        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and year = '" + year + "'");
        strWhere.append(" and month between '1' and '" + month + "'");
        strWhere.append(" and day between '1' and '" + day + "'");
        strWhere.append(" GROUP BY staticdate");
        strWhere.append(" ORDER BY sumvalue DESC LIMIT1");   // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "sum_rain_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    @Override
    public List<sum_rain_day_data> getQiHouByTemp10(String result) {
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        int month = calendar.get(calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("MAX(sumvalue) AS sumvalue");
        columns.add(" CONCAT(LPAD(month::text, 2, '0'), '月', LPAD(day::text, 2, '0'), '日') AS staticdate ");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

// 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and stationid IN (").append(result).append(")");
        strWhere.append(" and sumindicatorname like '%总雨量%'");  // 添加你需要的筛选条件
        strWhere.append(" and year = '" + year + "'");
        strWhere.append(" and month between '1' and '" + month + "'");
        strWhere.append(" and day between '1' and '" + day + "'");
        strWhere.append(" GROUP BY  LPAD(month::text, 2, '0'), LPAD(day::text, 2, '0')");
        strWhere.append(" ORDER BY staticdate");   // 限制只返回最大的一条记录
// 修正 whereCount 检查
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = new StringBuilder(strWhere.substring(4));  // 从第四个字符开始截取
        }
        selectRequest.setParam(strWhere.toString());  // 设置查询条件
        try {
            selectParam.put("method", "sum_rain_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    @Override
    public Object getQxFwDoc() throws SQLException, IOException, ClassNotFoundException {
        List<Map<String, Object>> result = new ArrayList<>();
        try {
            Connection connection = getConnection();
            // 只使用 Statement 或 PreparedStatement 中的一种
            String sql = "SELECT  t.producttype, t.productname, t.forecasttime,t.id FROM base_product t " +
                    "JOIN (SELECT producttype, MAX(forecasttime) AS latest_forecasttime FROM base_product GROUP BY producttype) latest_products " +
                    "ON t.producttype = latest_products.producttype AND t.forecasttime = latest_products.latest_forecasttime";
            // 使用 Statement 来执行 SQL 查询
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            // 处理 ResultSet，填充 result 列表
            while (resultSet.next()) {
                Map<String, Object> row = new HashMap<>();
                row.put("id", resultSet.getObject("id"));
                row.put("producttype", resultSet.getObject("producttype"));
                row.put("productname", resultSet.getObject("productname"));
                Date forecastDate = resultSet.getDate("forecasttime");
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String formattedDate = sdf.format(forecastDate);
                row.put("forecasttime", formattedDate);
                // row.put("forecasttime", resultSet.getObject("forecasttime"));
                // 如果表中有其他字段，可以继续添加
                result.add(row);
            }
            return result;
        } catch (Exception e) {
            log.error(e.getMessage());
            throw e;
        }


    }

    @Override
    public Object getRainByMonth(int month,String stationId) {
        // 获取当前时间
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("sumvalue");
        columns.add("day");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

        // 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(" stationid = '").append(stationId).append("'");
        strWhere.append(" and sumindicatorname like '%雨量%'");
        strWhere.append(" and month = ' ").append(month).append("'");
        strWhere.append(" and year = '").append(year).append("'");

        selectRequest.setParam(strWhere.toString());  // 设置查询条件

        try {
            selectParam.put("method", "sum_rain_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);

            // 将返回的 JSON 转换为 List<sum_rain_day_data>
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {});

            // 构建一个 1 到 31 天的降水数据
            Map<Integer, Double> rainDataMap = new HashMap<>();
            for (sum_rain_day_data data : dataList) {
                DecimalFormat df = new DecimalFormat("#.0");
                // 将小数点后只保留一位，放入map
                double formattedValue = Double.parseDouble(df.format(data.getSumvalue()));
                rainDataMap.put(data.getDay(), formattedValue);
            }

            // 创建一个完整的 31 天数据列表
            List<sum_rain_day_data> fullDataList = new ArrayList<>();
            for (int day = 1; day <= 31; day++) {
                sum_rain_day_data dayData = new sum_rain_day_data();
                dayData.setDay(day);
                // 如果某天的降水数据不存在，则填充为 0
                dayData.setSumvalue(rainDataMap.getOrDefault(day, 0.0));
                fullDataList.add(dayData);
            }

            return fullDataList;

        } catch (Exception e) {
            e.printStackTrace();  // 这里打印异常
        }

        return null;  // 如果发生异常，返回空值
    }
    @Override
    public Object getTempByMonth(int month,String stationId) {
        // 获取当前时间
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("sumvalue");
        columns.add("day");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

        // 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(" stationid = '").append(stationId).append("'");
        strWhere.append(" and sumindicatorname like '%平均气温%'");
        strWhere.append(" and month = ' ").append(month).append("'");
        strWhere.append(" and year = '").append(year).append("'");

        selectRequest.setParam(strWhere.toString());  // 设置查询条件

        try {
            selectParam.put("method", "sum_temp_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);

            // 将返回的 JSON 转换为 List<sum_rain_day_data>
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {});

            // 构建一个 1 到 31 天的降水数据
            Map<Integer, Double> rainDataMap = new HashMap<>();
            for (sum_rain_day_data data : dataList) {
                DecimalFormat df = new DecimalFormat("#.0");
                // 将小数点后只保留一位，放入map
                double formattedValue = Double.parseDouble(df.format(data.getSumvalue()));
                rainDataMap.put(data.getDay(), formattedValue);
            }

            // 创建一个完整的 31 天数据列表
            List<sum_rain_day_data> fullDataList = new ArrayList<>();
            for (int day = 1; day <= 31; day++) {
                sum_rain_day_data dayData = new sum_rain_day_data();
                dayData.setDay(day);
                // 如果某天的降水数据不存在，则填充为 0
                dayData.setSumvalue(rainDataMap.getOrDefault(day, 0.0));
                fullDataList.add(dayData);
            }

            return fullDataList;

        } catch (Exception e) {
            e.printStackTrace();  // 这里打印异常
        }

        return null;  // 如果发生异常，返回空值
    }

    @Override
    public Object getWindByMonth(int month,String stationId) {
        // 获取当前时间
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);  // 获取当前年份
        List<sum_rain_day_data> dataList = new ArrayList<sum_rain_day_data>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("sumvalue");
        columns.add("day");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

        // 构建查询条件
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(" stationid = '").append(stationId).append("'");
        strWhere.append(" and sumindicatorname = '最大风速'");
        strWhere.append(" and month = ' ").append(month).append("'");
        strWhere.append(" and year = '").append(year).append("'");

        selectRequest.setParam(strWhere.toString());  // 设置查询条件

        try {
            selectParam.put("method", "sum_wind_day_data");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);

            // 将返回的 JSON 转换为 List<sum_rain_day_data>
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sum_rain_day_data>>() {});

            // 构建一个 1 到 31 天的降水数据
            Map<Integer, Double> rainDataMap = new HashMap<>();
            for (sum_rain_day_data data : dataList) {
                DecimalFormat df = new DecimalFormat("#.0");
                // 将小数点后只保留一位，放入map
                double formattedValue = Double.parseDouble(df.format(data.getSumvalue()));
                rainDataMap.put(data.getDay(), formattedValue);
            }

            // 创建一个完整的 31 天数据列表
            List<sum_rain_day_data> fullDataList = new ArrayList<>();
            for (int day = 1; day <= 31; day++) {
                sum_rain_day_data dayData = new sum_rain_day_data();
                dayData.setDay(day);
                // 如果某天的降水数据不存在，则填充为 0
                dayData.setSumvalue(rainDataMap.getOrDefault(day, 0.0));
                fullDataList.add(dayData);
            }

            return fullDataList;

        } catch (Exception e) {
            e.printStackTrace();  // 这里打印异常
        }

        return null;  // 如果发生异常，返回空值
    }
    private static Connection getConnection() throws SQLException, ClassNotFoundException, IOException {
        try {
            Properties prop = new Properties();
            InputStream in = ComDisplayServiceImpl.class.getClassLoader().getResourceAsStream("dbconfig.properties");
            prop.load(in);
            Connection connection;
            Class.forName("org.postgresql.Driver");
            return DriverManager.getConnection(prop.getProperty("postgresql.servant.url"), prop.getProperty("postgresql.username"), prop.getProperty("postgresql.password"));

        } catch (Exception e) {
            log.error(e.getMessage());
            throw e;
        }
    }

}
